How to get all token balances for a wallet: token balances API vs RPC
Every token a wallet holds, two ways: JSON-RPC calls (eth_getBalance, balanceOf, eth_getLogs) or one indexed API call, with decimals, prices, spam and history.
On this page
- Token balances over RPC: what it takes
- Step 1: Read balances for the tokens you know
- Step 2: Find the tokens a wallet holds
- Step 3: Get all token balances in one API call
- Handle errors from the token balances API
- Past balances: archive nodes vs one parameter
- RPC vs token balances API, side by side
- When to use RPC, and when an API
- Frequently asked questions
- Next steps
A wallet's token balances are not stored in one place on chain. The native balance (ETH on Ethereum) belongs to the account, but each ERC-20 balance lives inside that token's own contract. So "what does this wallet hold?" has two answers in code: ask a node about every token contract yourself over JSON-RPC, or ask an indexed API that has already done that work.
This guide does both for the same Ethereum wallet, shows where the RPC route needs extra work (finding the tokens, decimals, prices, spam, past balances, other chains) and when RPC is still the right tool. If you are new to nodes, start with what an RPC node is and how it works.
Token balances over RPC: what it takes
The standard Ethereum JSON-RPC API has no method that returns every token an address holds. You build the list from three primitives:
eth_getBalancereturns the native balance, in wei, at a block.eth_callruns a read-only contract function. ERC-20'sbalanceOf(address)gives the wallet's raw balance of one token, anddecimals()tells you how to scale it. That is two calls per token, and you must already know the token's contract address.eth_getLogsfindsTransferevents sent to the wallet, which is how you discover which token contracts to ask in the first place.
Some node providers add their own, non-standard methods for this, such as Alchemy's alchemy_getTokenBalances. They work only on that provider. Per Alchemy's docs (checked 22 November 2026), it returns a contractAddress and a hex-encoded tokenBalance per token; the name, symbol and decimals come from a separate alchemy_getTokenMetadata call per token, and prices from another API.
Step 1: Read balances for the tokens you know
Before you start: Node.js 18 or later (for the built-in fetch; the RPC code was run on Node 22), any Ethereum JSON-RPC endpoint in the RPC_URL environment variable, and, for Step 3, a GoldRush API key in GOLDRUSH_API_KEY. Every code block on this page goes in the same file, in order, and later blocks reuse rpc, word, formatUnits, wallet and balancesFromGoldRush from earlier ones. Save it as balances.mjs, so Node runs it as an ES module and top-level await works, and run it with node balances.mjs.
This function sends eth_getBalance plus balanceOf and decimals for each token in one JSON-RPC batch, and scales each raw balance by its decimals.
const RPC_URL = process.env.RPC_URL; // any Ethereum JSON-RPC endpoint // One JSON-RPC call.async function rpc(method, params) { const res = await fetch(RPC_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }), }); const reply = await res.json(); if (reply.error) throw new Error(reply.error.message); return reply.result;} // Several calls in one HTTP request, results returned in the order sent.async function rpcBatch(calls) { const body = calls.map(([method, params], id) => ({ jsonrpc: "2.0", id, method, params })); const res = await fetch(RPC_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); const replies = await res.json(); // An endpoint that doesn't take batches answers with one error object. if (!Array.isArray(replies)) throw new Error(replies.error?.message ?? "batch not supported"); replies.sort((a, b) => a.id - b.id); return replies.map((r) => { if (r.error) throw new Error(r.error.message); return r.result; });} const BALANCE_OF = "0x70a08231"; // balanceOf(address)const DECIMALS = "0x313ce567"; // decimals()const word = (address) => address.toLowerCase().replace("0x", "").padStart(64, "0"); // A raw integer in a token's smallest unit as an exact decimal string. Number(raw) / 10 ** decimals would round// large balances, since an 18-decimal balance passes JavaScript's safe integer range.function formatUnits(raw, decimals) { const digits = raw.toString().padStart(decimals + 1, "0"); const whole = digits.slice(0, digits.length - decimals); const fraction = digits.slice(digits.length - decimals).replace(/0+$/, ""); return fraction ? `${whole}.${fraction}` : whole;} // The native balance plus one balance per listed token, at a block ("latest" or a hex block number).async function balancesFromRpc(wallet, tokens, block = "latest") { const calls = [["eth_getBalance", [wallet, block]]]; for (const t of tokens) { calls.push(["eth_call", [{ to: t.address, data: BALANCE_OF + word(wallet) }, block]]); calls.push(["eth_call", [{ to: t.address, data: DECIMALS }, block]]); } const [native, ...results] = await rpcBatch(calls); const rows = [{ symbol: "ETH", raw: BigInt(native), decimals: 18 }]; tokens.forEach((t, i) => { // "0x" means no contract answered: a wrong address, or a token on another chain. if (results[2 * i] === "0x") throw new Error(`${t.symbol} (${t.address}) is not a token contract here`); rows.push({ symbol: t.symbol, raw: BigInt(results[2 * i]), decimals: Number(BigInt(results[2 * i + 1])) }); }); // Raw integers in each token's smallest unit: scale by decimals before you show them. return rows.map((r) => ({ ...r, amount: formatUnits(r.raw, r.decimals) }));} const TOKENS = [ { symbol: "USDC", address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" }, { symbol: "USDT", address: "0xdac17f958d2ee523a2206206994597c13d831ec7" }, { symbol: "WETH", address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" },];const wallet = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; console.table(await balancesFromRpc(wallet, TOKENS));Three things to notice:
- You supply the token list. The node answers for the contracts you name and nothing else. A token the wallet holds but you didn't list is invisible.
- Decimals differ per token. USDC and USDT use 6, WETH and most tokens 18. A balance of
1000000is 1 USDC but a millionth of a millionth of a WETH, so you readdecimals()for every token, or keep them in your own table. - There are no prices. A balance is a token amount. Its value in dollars comes from a separate price source you call and keep in sync.
The batch sends 1 + 2 × N calls for N tokens in one HTTP request; the node still runs each one. Check how your provider counts batched calls, and whether it accepts batches at all.
Step 2: Find the tokens a wallet holds
To build the token list from the chain itself, scan for ERC-20 Transfer events whose recipient (the third topic) is the wallet. Every contract that ever sent it a token is a candidate; then you read each one's balance as in Step 1, since many will be zero.
// keccak256("Transfer(address,address,uint256)")const TRANSFER = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"; // Token contracts that sent the wallet anything between two blocks, scanned in chunks.async function tokensReceived(wallet, fromBlock, toBlock, chunk = 500) { const contracts = new Set(); for (let start = fromBlock; start <= toBlock; start += chunk) { const end = Math.min(start + chunk - 1, toBlock); const logs = await rpc("eth_getLogs", [ { fromBlock: "0x" + start.toString(16), toBlock: "0x" + end.toString(16), topics: [TRANSFER, null, "0x" + word(wallet)], }, ]); for (const log of logs) contracts.add(log.address); } return [...contracts];} const tip = Number(await rpc("eth_blockNumber", []));console.log(await tokensReceived(wallet, tip - 3_000, tip));This is where RPC gets expensive. Providers cap the block range of one eth_getLogs request, so a wallet's full history means scanning from its first transaction to today in small windows. When we ran this code on 21 November 2026 against five free public Ethereum endpoints (not recorded by name, so read the figures as an example of the spread, not as any one provider's limit), three capped the range at 50, 100 and 800 blocks, and one refused log queries without a contract address. Ethereum adds a block about every 12 seconds, roughly 2.6 million a year, so even at 800 blocks per request one year of history is over 3,000 requests.
The scan also finds things you don't want. Over just the last 3,000 blocks, it returned USDT and an unknown token contract that had sent the wallet an unsolicited transfer. Airdropped spam tokens look exactly like real ones in the logs, so you need your own rules or list to filter them out. Tokens that rebase (stETH, aTokens) change balance without a Transfer to the holder, which is another reason to read balanceOf rather than sum transfers.
Step 3: Get all token balances in one API call
An indexed API runs the nodes and indexes the transfers for you, across chains. With the token balance API from the GoldRush Foundational API, one balances_v2 call returns the native token and every ERC-20 the wallet holds on a chain, each with its decimals, symbol, name, a USD quote and a spam flag. Its credit cost is 1 per call, however many tokens the wallet holds.
const API = "https://api.covalenthq.com/v1";const headers = { Authorization: `Bearer ${process.env.GOLDRUSH_API_KEY}` }; // Every token a wallet holds on one chain, native token included, priced in USD.// Pass { date: "YYYY-MM-DD" } or { "block-height": "..." } for the balances at a past point.async function balancesFromGoldRush(chain, wallet, at = {}) { const past = Object.keys(at).length > 0; const path = past ? "historical_balances" : "balances_v2"; const query = new URLSearchParams({ "quote-currency": "USD", "no-spam": "true", ...at }); const res = await fetch(`${API}/${chain}/address/${wallet}/${path}/?${query}`, { headers }); // Errors come back as { data: null, error: true, error_code, error_message }; a request with no // Authorization header gets an HTML 401 from the edge instead, so don't assume the body is JSON. const body = await res.json().catch(() => null); if (!res.ok || !body || body.error) { throw new Error(`GoldRush ${body?.error_code ?? res.status}: ${body?.error_message ?? res.statusText}`); } return body.data.items .filter((t) => t.balance !== "0") .map((t) => ({ symbol: t.contract_ticker_symbol, raw: BigInt(t.balance), decimals: t.contract_decimals ?? 0, amount: formatUnits(BigInt(t.balance), t.contract_decimals ?? 0), usd: t.quote, }));} const address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";console.table(await balancesFromGoldRush("eth-mainnet", address));It returns rows in the same shape as balancesFromRpc, so you can swap one for the other. Each item in the response carries what the RPC route had to assemble. Here is one, abridged, from a recorded response for another Ethereum wallet:
{ "contract_decimals": 6, "contract_name": "Tether USD", "contract_ticker_symbol": "USDT", "contract_address": "0xdac17f958d2ee523a2206206994597c13d831ec7", "last_transferred_at": "2026-10-31T09:31:59.000Z", "type": "stablecoin", "is_spam": false, "is_native_token": false, "balance": "1175464712876362", "balance_24h": "1175464712876362", "quote_rate": 0.99606574, "quote": 1170840000}balanceis the raw integer as a string; divide by10^contract_decimalsto display it (formatUnitsdoes that without rounding), or keep it as aBigIntfor accounting.quote_rateis the token's price andquotethe balance's value in the quote currency.balance_24handquote_24hgive the change over a day without a second request.is_spamflags suspected spam, andno-spam=trueremoves it from the response on Foundational Chains.- The native token is one of the items, marked by
is_native_token. If that is all you need, the native token balance endpoint returns just it (credit cost: 0.5 per call). - The wallet can also be an ENS name such as
vitalik.eth, which the API resolves.
Handle errors from the token balances API
A failed request returns the same envelope as a successful one, with data set to null. The error handling docs show this body for a chain the API doesn't serve:
{ "data": null, "error": true, "error_message": "Chain nosuchchain-mainnet not supported.", "error_code": 501 }A 501 means the request was well formed but the chain or endpoint can't serve it, so retrying it unchanged returns the same answer: fix the chain name, or check which chains the endpoint lists. historical_balances serves fewer chains than balances_v2 (below), so a past-date call on a chain it does not list is one way to get it. A request sent with no Authorization header is refused by the edge proxy with an HTML 401 page, not JSON, which is why balancesFromGoldRush doesn't assume the body parses. Error responses cost no credits.
Past balances: archive nodes vs one parameter
Over RPC, a past balance is the same eth_getBalance and eth_call with a block number instead of "latest". A full node only keeps recent state, so for older blocks you need an archive node, your own or a provider's. One of the public endpoints we tried refused past-block reads without a personal token. And you still need the token list as of that block, which means the log scan up to it.
With GoldRush, pass date or block-height and balancesFromGoldRush calls the historical token balances endpoint instead, which returns the whole wallet as of that point with the price on that day (credit cost: 1 per call):
// The wallet as of 31 December 2025, priced on that dayconsole.table(await balancesFromGoldRush("eth-mainnet", address, { date: "2025-12-31" }));Historical balances work on the 6 chains the endpoint lists: Ethereum, Polygon, BNB Smart Chain (BSC), Base, Optimism, and Gnosis.
RPC vs token balances API, side by side
| Raw JSON-RPC | GoldRush token balances API | |
|---|---|---|
| Calls for a wallet on one chain | 1 + 2 per token, plus the log scan to find the tokens | 1 (balances_v2, credit cost 1 per call) |
| Which tokens | Only the contracts you list or discover | Every ERC-20 the wallet holds, plus the native token |
| Decimals, names, symbols | Separate calls per token | In every item |
| Prices | Not available; bring a price source | quote_rate and quote, in a choice of quote currencies |
| Spam | Your own filtering | is_spam flag; no-spam=true on Foundational Chains |
| Past balances | Archive node, plus the token list as of that block | historical_balances with date or block-height (6 chains) |
| Several chains | One endpoint, and one scan, per chain | Change the chain name, or the wallet balance API for one address across EVM chains (2.5 per call) |
| NFTs | ERC-721 balanceOf gives a count per collection, not the tokens |
The NFT wallet API (1 per call) |
| Sending transactions | Yes | No: the API is read-only |
When to use RPC, and when an API
Use raw RPC when you need what only a node does: sending transactions, reading live contract state the moment a block lands, simulating calls, or checking a handful of tokens you already know (a dapp reading its own token's balance, a token-gated page checking one contract). Two calls per token is cheap when the list is short and fixed.
Use a token balances API when the question is about the whole wallet: wallet and portfolio screens, tax and accounting exports, treasury dashboards, compliance checks, or anything across many tokens, many wallets or many chains. That is where the RPC route turns into running your own indexer, a price feed and a spam list.
Most apps use both. GoldRush also serves GoldRush JSON-RPC, so the same API key covers node calls and indexed data. If you are weighing an explorer API instead, the Etherscan API alternatives guide makes the same balances call against Etherscan.
Frequently asked questions
How do I get all token balances for a wallet address?
Over standard JSON-RPC there is no single call: you read the native balance with eth_getBalance, find the token contracts the wallet has received from Transfer logs with eth_getLogs, then call balanceOf and decimals on each. An indexed API such as GoldRush's balances_v2 endpoint returns the native token and every ERC-20 the wallet holds on a chain in one call, with decimals, prices and a spam flag.
Can eth_getBalance return ERC-20 token balances?
No. eth_getBalance returns only the native balance (ETH on Ethereum) in wei. An ERC-20 balance is stored in the token's contract, so you read it with an eth_call to that contract's balanceOf(address) function, one call per token.
Why do I need to divide token balances by decimals?
Tokens store balances as whole integers in their smallest unit. decimals() says where the decimal point goes: a USDC balance of 1000000 with 6 decimals is 1 USDC. RPC calls and the GoldRush API both return the raw integer; GoldRush includes contract_decimals in each item so you don't need a second call.
How do I get a wallet's token balances at a past date?
Over RPC, call eth_getBalance and balanceOf with the past block number, against an archive node, for each token the wallet held at that block. With GoldRush, call the historical token balances endpoint with a date (YYYY-MM-DD) or block-height, and it returns the whole wallet as of that point with that day's prices.
Does the token balances API replace my RPC provider?
No. It is read-only: it can't send transactions, and it isn't meant for reading arbitrary contract state the instant a block lands. Use RPC for writes and live contract reads, and the API for wallet-wide balances, prices and history.
Next steps
- Token balance API reference: every
balances_v2parameter and response field. - Historical token balances reference: balances at a block or date.
- What is an RPC node and how does it work: full vs archive nodes and how RPC providers scale.
- How to get token holder data: the other direction, every wallet that holds one token.
- Start a free trial and run the code above with your own key.