How to Access the GoldRush API Using the Viem Framework: A Comprehensive Guide

This guide will walk you through setting up and using the GoldRush API with the Viem framework, enhancing your blockchain projects with minimal API calls.

The GoldRush API, renowned for its unified approach to blockchain data, offers developers seamless access to detailed information across over 200 blockchains. With the integration of GoldRush's Unified API into the Viem framework, leveraging the TypeScript-based Viem Compatible SDK, developers can now efficiently utilize blockchain data in application development. This guide will walk you through setting up and using the GoldRush API with the Viem framework, enhancing your blockchain projects with minimal API calls.

Why Use GoldRush with Viem?

GoldRush provides a robust solution for accessing comprehensive blockchain data, including transactions, balances, and NFTs, with industry-leading performance. The integration with Viem allows developers to:

  • Access data across multiple blockchains seamlessly.

  • Reduce development overhead with simplified API interactions.

  • Implement features quickly with high-level abstractions and pre-built functions.

Getting Started with GoldRush and Viem

1

Installation

First, ensure you have Node.js installed on your system. Then, you can install the necessary packages using npm or Yarn:
npm install viem @covalenthq/client-viem-sdk
or
yarn add viem @covalenthq/client-viem-sdk
2

Setting Up a Client

Before you can make any API calls, you need to obtain a GoldRush API key. Sign up at the GoldRush website and retrieve your key from the API Keys tab. Once you have your API key, you can set up your client as follows:

import { createClient, http } from 'viem';
import { mainnet } from 'viem/chains';
import { publicActionCovalent } from '@covalenthq/client-viem-sdk';

const client = createClient({
  chain: mainnet,
  transport: http("YOUR_RPC_URL")  // Replace "YOUR_RPC_URL" with your RPC provider URL
}).extend(publicActionCovalent("YOUR_API_KEY"));
3

Consuming Actions with GoldRush

With the client set up, you can now access various blockchain data through the GoldRush API. Here are some examples of actions you can perform:
Fetch Token Balances:
const tokenBalances = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "demo.eth"); console.log(tokenBalances.data);
Get Address Activity:
const walletActivity = await client.BaseService.getAddressActivity("demo.eth"); console.log(walletActivity);
Retrieve NFTs:
const nfts = await client.NftService.getNftsForAddress("eth-mainnet", "demo.eth"); console.log(nfts);
Check Historical NFT Floor Prices:
const floorPrices = await client.NftService.getNftMarketFloorPrice("eth-mainnet", "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"); console.log(floorPrices);

Conclusion

Integrating the GoldRush API with the Viem framework empowers developers to build more dynamic, data-rich blockchain applications. By following this guide, you can enhance your applications with extensive blockchain data accessible through a unified API, ensuring your projects are both powerful and efficient. For further details and more advanced use cases, refer to the README documentation provided with the @covalenthq/client-viem-sdk.

Read more