Getting started with the GoldRush TypeScript SDK

GoldRush TeamUpdated 10 min read

Use the GoldRush TypeScript SDK to fetch wallet balances, transactions, NFTs, approvals and prices: services, errors, pagination, chain names and viem.

What the GoldRush SDK is

The GoldRush TypeScript SDK, published on npm as @covalenthq/client-sdk, is the official client for the GoldRush blockchain data API. One GoldRushClient object gives you typed methods for wallet balances, transaction history, NFTs, token approvals, historical prices, blocks and event logs, on every chain GoldRush supports. Its per-chain wallet methods accept ENS and other name-service names in place of an address, and it turns paginated endpoints into async iterators and retries rate-limited requests for you.

If you have never made a call, the Foundational API quickstart installs the SDK and fetches one wallet's balances in four steps. This guide picks up from there: what each service does, how to handle errors and pages, how to name chains, and how to use the SDK next to viem.

The client used to be called CovalentClient. Code written against it, or against the old XykService, needs updating: the client is now GoldRushClient, and the xy=k DEX endpoints are gone.

Install and create a client

Before you start:

  • Node.js 18 or later.
  • A GoldRush API key in the GOLDRUSH_API_KEY environment variable. Sign up for the 14-day free trial to get one.
  • An Ethereum JSON-RPC endpoint in RPC_URL, for the viem example only.
  • A TypeScript runner. Every example uses top-level await, so save each one as its own .mts file (an ES module) and run it with npx tsx example.mts.

Install the SDK, viem for the last example, and tsx, pinned to the versions this guide was written against:

npm install @covalenthq/client-sdk@3.0.9 viem@2.52.2npm install -D tsx@4.23.15

Create one client and reuse it. The optional second argument sets how many requests run at once and how 429 rate-limit responses are retried:

import { GoldRushClient } from "@covalenthq/client-sdk"; // Throws a 401-shaped error right away if the key is missing or malformedconst client = new GoldRushClient(process.env.GOLDRUSH_API_KEY ?? "", {    threadCount: 2, // concurrent requests (default 2)    enableRetry: true, // retry a 429 rate-limit response (default true)    maxRetries: 2, // default 2    retryDelay: 1500, // ms between retries (default 1500)    debug: false, // true logs each request's URL, status and time}); const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "demo.eth");console.log(resp.error ? resp.error_message : resp.data.items?.length);

Keep the key on a server. The SDK runs in browsers too, but a key shipped in front-end code can be read by anyone who opens the page.

The SDK's services and what each call costs

Each group of endpoints is a property of the client. Each call is billed in API credits at the endpoint's rate, shown here for the example method; every page an iterator fetches is a separate call.

Service What it returns Example method Credits
BalanceService Token balances, historical balances, ERC-20 transfers, token holders getTokenBalancesForWalletAddress 1 per call
AllChainsService One wallet across every chain: activity, balances, transactions getAddressActivity 0.5 per call
TransactionService Wallet transaction history, single transactions, summaries getAllTransactionsForAddress 0.1 per item
NftService NFTs a wallet holds, ownership checks getNftsForAddress 1 per call
SecurityService Token approvals and the value each spender can move getApprovals 2 per call
PricingService Historical token prices, DEX pool spot prices getTokenPrices 1 per call
BitcoinService Bitcoin balances for addresses and HD wallets (xpub), transactions getBitcoinHdWalletBalances 0.1 per item
BaseService Blocks, event logs, gas prices, chain lists, name resolution getLogEventsByAddress 0.01 per item

The same client also has a StreamingService for real-time data over WebSockets, covered in the Streaming API docs.

A few calls worth knowing early:

  • BalanceService.getTokenBalancesForWalletAddress is the token balance API: every token one wallet holds on one chain, with spot prices.
  • AllChainsService.getMultiChainBalances returns a wallet's balances across chains in one call (2.5 per call).
  • BalanceService.getErc20TransfersForWalletAddress lists a wallet's transfers of one token (0.05 per item).
  • BalanceService.getTokenHoldersV2ForTokenAddress lists every holder of a token (0.02 per item); the token holder guide walks through it.

Example: a wallet overview

Four calls give you the core of a wallet API screen: the chains a wallet has used, its tokens with prices, its NFTs and its open approvals.

import { GoldRushClient, calculatePrettyBalance } from "@covalenthq/client-sdk"; const client = new GoldRushClient(process.env.GOLDRUSH_API_KEY ?? "");const wallet = "demo.eth"; // ENS, Lens, Unstoppable and RNS names resolve // 1. Which chains has the wallet used? One call across every chain.const activity = await client.AllChainsService.getAddressActivity(wallet);if (activity.error) throw new Error(activity.error_message);console.log(    "Active on:",    (activity.data.items ?? []).map((c) => c.name)); // 2. Its tokens on one chain, with spot prices, spam removedconst balances = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", wallet, {    noSpam: true,    quoteCurrency: "USD",});if (balances.error) throw new Error(balances.error_message);for (const token of balances.data.items ?? []) {    // balance is a bigint in the token's smallest unit    const amount = calculatePrettyBalance(token.balance ?? 0n, token.contract_decimals ?? 0);    console.log(token.contract_ticker_symbol, amount, token.pretty_quote);} // 3. Its NFTs on the same chain, grouped by collectionconst nfts = await client.NftService.getNftsForAddress("eth-mainnet", wallet);if (nfts.error) throw new Error(nfts.error_message);for (const collection of nfts.data.items ?? []) {    console.log(collection.contract_name, collection.nft_data?.length, "held");} // 4. Its open token approvals, with the value each spender could moveconst approvals = await client.SecurityService.getApprovals("eth-mainnet", wallet);if (approvals.error) throw new Error(approvals.error_message);for (const a of approvals.data.items ?? []) {    console.log(a.ticker_symbol, a.value_at_risk);}

Two things the SDK does to the raw JSON: token amounts such as balance arrive as bigint, and timestamps as Date. Every response field is typed as possibly null, which is why the example falls back with ??. The types are exported (BalanceItem, Transaction, NftTokenContractBalanceItem and the rest), so you can annotate your own functions with them.

Handle errors from the SDK

SDK methods don't throw when a request fails. Each one resolves to an object with data, error, error_code and error_message: when error is true, data is null. Check error before you touch data, or convert the response once with a helper:

import { GoldRushClient, type GoldRushResponse } from "@covalenthq/client-sdk"; const client = new GoldRushClient(process.env.GOLDRUSH_API_KEY ?? ""); // Every method resolves to { data, error, error_code, error_message }// instead of throwing. Turn that into an exception once, here.function unwrap<T>(resp: GoldRushResponse<T>): T {    if (resp.error) {        throw new Error(`GoldRush ${resp.error_code}: ${resp.error_message}`);    }    return resp.data;} const balances = unwrap(await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "demo.eth"));console.log(balances.address, balances.items?.length);

When the API answers with an error, the SDK passes its error_code and error_message through. The error handling docs show this body for a chain the API doesn't serve, and the SDK method resolves to the same four fields:

{ "data": null, "error": true, "error_message": "Chain nosuchchain-mainnet not supported.", "error_code": 501 }

A 501 is a stable answer, not an outage: the chain or endpoint can't serve that request, so retrying it unchanged returns the same error. Fix the chain name, or check supported chains for the endpoint. The SDK retries only 429 rate-limit responses; error handling lists which other codes are worth a retry.

The one place the SDK does throw is the constructor. new GoldRushClient() with a missing or malformed key throws this object before any request is made (from the SDK 3.0.9 source), so wrap it in try if the key comes from user input:

{    "data": null,    "error": true,    "error_code": 401,    "error_message": "Invalid or missing API key (sign up at https://goldrush.dev/platform/apikey)"}

Page through long results

Endpoints that can return more than one page have two methods in the SDK:

  • the plain method (getAllTransactionsForAddress, getErc20TransfersForWalletAddress, getTokenHoldersV2ForTokenAddress, getLogEventsByAddress, getLogEventsByTopicHash, getBlockHeights) returns an async iterator that fetches page after page;
  • the ByPage method (getAllTransactionsForAddressByPage and so on) returns one page.

Each step of the iterator is a whole page, a response with its own error and data.items, not a single item. Collect the items yourself and stop when you have enough:

import { GoldRushClient, type Transaction } from "@covalenthq/client-sdk"; const client = new GoldRushClient(process.env.GOLDRUSH_API_KEY ?? ""); // Each step of the iterator is one page (a full response), not one item.// It stops after the last page, or after yielding an error response.const txs: Transaction[] = [];for await (const page of client.TransactionService.getAllTransactionsForAddress("eth-mainnet", "demo.eth", {    noLogs: true,})) {    if (page.error) throw new Error(page.error_message);    txs.push(...(page.data.items ?? []));    if (txs.length >= 500) break; // every page is billed: stop when you have enough}console.log(txs.length, "transactions, newest first");

Transaction history costs 0.1 per item, so a wallet with years of activity is worth capping. For a "load more" button, fetch one page and step from it. Transaction pages carry prev() and next() functions that fetch the neighbouring page:

import { GoldRushClient } from "@covalenthq/client-sdk"; const client = new GoldRushClient(process.env.GOLDRUSH_API_KEY ?? ""); // One page at a time, for a "load more" buttonconst first = await client.TransactionService.getAllTransactionsForAddressByPage("eth-mainnet", "demo.eth");if (first.error) throw new Error(first.error_message);console.log("page", first.data.current_page, first.data.items?.length); // prev() steps to older transactions, next() back to newer onesif (first.data.prev) {    const older = await first.data.prev();    if (!older.error) console.log("page", older.data.current_page);}

Without the SDK you do the same by hand: request a page of the REST endpoint, read the next page's link or number from the response and repeat until there are no more.

Name a chain

Every per-chain method takes the chain first, in any of four forms:

  • the chain name as a string, such as "eth-mainnet", "base-mainnet" or "matic-mainnet";
  • the chain ID as a number, such as 1 or 8453;
  • the ChainName enum, such as ChainName.BASE_MAINNET;
  • the ChainID enum, such as ChainID.ETH_MAINNET.

The enums are exported from the package, and TypeScript rejects a name it doesn't know. Supported chains lists every chain name and which endpoints each chain serves.

Cross-chain methods on AllChainsService take no chain at all. For prices, the second argument is the quote currency:

import { GoldRushClient } from "@covalenthq/client-sdk"; const client = new GoldRushClient(process.env.GOLDRUSH_API_KEY ?? "");const USDC = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; // Daily USD prices for a token over a date rangeconst prices = await client.PricingService.getTokenPrices("eth-mainnet", "USD", USDC, {    from: "2026-10-01",    to: "2026-10-31",});if (prices.error) throw new Error(prices.error_message);for (const p of prices.data[0]?.items ?? []) {    console.log(p.date, p.pretty_price);}

Using the GoldRush SDK with viem

viem and the GoldRush SDK do different jobs, and most dapps want both:

  • viem talks to a node over JSON-RPC. Use createPublicClient for live reads (the latest block, a balance, a readContract call) and a wallet client to sign and send transactions.
  • GoldRush answers questions a node can't answer in one call: every token a wallet holds with prices, its full transaction history, its NFTs, the chains it has used.

Create both clients side by side:

import { GoldRushClient } from "@covalenthq/client-sdk";import { createPublicClient, formatEther, http } from "viem";import { mainnet } from "viem/chains"; // viem: talk to a node over JSON-RPC (reads now, and writes with a wallet client)const rpc = createPublicClient({ chain: mainnet, transport: http(process.env.RPC_URL) }); // GoldRush: indexed data a node can't answer in one callconst goldrush = new GoldRushClient(process.env.GOLDRUSH_API_KEY ?? ""); const address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // Live from the node: the latest block and the ETH balance at itconst [block, wei] = await Promise.all([rpc.getBlockNumber(), rpc.getBalance({ address })]);console.log(`Block ${block}: ${formatEther(wei)} ETH`); // From GoldRush: every token the address holds, priced, in one callconst balances = await goldrush.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", address, {    noSpam: true,});if (balances.error) throw new Error(balances.error_message);const tokens = balances.data.items ?? [];console.log(`${tokens.length} tokens, ${tokens.reduce((s, t) => s + (t.quote ?? 0), 0).toFixed(2)} USD`);

The two map onto each other: viem's mainnet is GoldRush's eth-mainnet, and you can pass mainnet.id (a chain ID) straight to a GoldRush method.

An earlier package, @covalenthq/client-viem-sdk, added GoldRush methods to a viem client with .extend(). It is deprecated on npm and no longer maintained. Use the standard @covalenthq/client-sdk next to viem as shown above. For more on what a node does and doesn't answer, see what an RPC node is.

Frequently asked questions

Is CovalentClient the same as GoldRushClient?

Yes. Covalent's data API is now GoldRush, and the SDK's client class was renamed from CovalentClient to GoldRushClient. The npm package name, @covalenthq/client-sdk, stayed the same. Update the import and the constructor, and replace any XykService calls: those endpoints were retired.

Is there a GoldRush SDK for Python?

The official SDK is TypeScript. The older covalent-api-sdk Python package has had no release since April 2024 and isn't in the GoldRush docs. From Python, call the REST API with any HTTP client and send your key as a Bearer token; the API reference shows each endpoint's URL and parameters.

Can I use GoldRush with viem?

Yes. Use viem for JSON-RPC reads and transactions and a GoldRushClient for indexed data such as balances, transaction history and NFTs, in the same app. The old @covalenthq/client-viem-sdk extension is deprecated; use @covalenthq/client-sdk instead.

Does the SDK handle pagination for me?

Yes. Methods such as getAllTransactionsForAddress return an async iterator that fetches each page in turn, and the ByPage variants return a single page. Each step of the iterator is a page, so read page.data.items, and break out of the loop once you have what you need, since every page is billed.

How much does the SDK cost to use?

The SDK is free and open source. Each call is billed in API credits at the endpoint's rate, such as 1 per call for token balances or 0.1 per item for transaction history. The free trial includes 25,000 credits, and the pricing calculator estimates a month of calls.

Next steps

Get new guides by email

New tutorials and best practices for building with blockchain data, sent as they're published.