Solana - Error "Too many accounts requested, limit is 10,000,000"
Tatum's token balance endpoint can't read Solana tokens whose program owns over 10 million accounts; use the getTokenAccountsByOwner RPC method instead.
The Solana error Too many accounts requested, limit is 10,000,000 comes from Tatum's token balance endpoint when the token program behind the token owns more than 10 million accounts. The endpoint has no workaround for this limit. Get the balance with the Solana RPC method getTokenAccountsByOwner instead, filtered by the token's mint address.
Symptom
When you use Tatum's API to retrieve the token balance of a Solana address, you get the following error:
{
"statusCode": 403,
"errorCode": "erc20.get.error",
"message": "Get operation failed",
"cause": "failed to get accounts owned by program ####: Too many accounts requested, limit is 10,000,000",
"dashboardLog": "https://dashboard.tatum.io/logs?id=####"
}Cause
This error occurs because the endpoint has a default limitation on the number of accounts that can be requested in a single operation.
The error arises when the number of accounts owned by a token program exceeds the threshold of 10 million accounts.
Solution
At present, there are no workarounds for this limitation via the Tatum token balance endpoint. Use the Solana RPC instead:
-
Call
getTokenAccountsByOwnerwith the wallet address and a filter with the token'smint. This example gets the USDC balance of a wallet:curl --location 'https://solana-mainnet.gateway.tatum.io' \ --header 'Content-Type: application/json' \ --header 'x-api-key: {YOUR_API_KEY}' \ --data '{ "jsonrpc": "2.0", "id": 1, "method": "getTokenAccountsByOwner", "params": [ "HMKa355WmAEPDMakaWrS47goUiggsonDiLH8kicck6pL", { "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" }, { "encoding": "jsonParsed" } ] }' -
Read the balance from
account.data.parsed.info.tokenAmountof each returned token account.amountis the raw integer,decimalsthe token's decimals anduiAmountStringthe balance in whole tokens (response trimmed):{ "jsonrpc": "2.0", "result": { "context": { "slot": 474516414 }, "value": [ { "pubkey": "JAneVaFUCJksJ3r9LUDuEHLdAT5zJh5KAZogn4mWir7r", "account": { "data": { "program": "spl-token", "parsed": { "info": { "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "owner": "HMKa355WmAEPDMakaWrS47goUiggsonDiLH8kicck6pL", "tokenAmount": { "amount": "45218138", "decimals": 6, "uiAmount": 45.218138, "uiAmountString": "45.218138" } }, "type": "account" } } } } ] }, "id": 1 } -
Add up the amounts if
valuelists more than one token account for the mint. -
To list every token of the wallet, replace the mint filter with
{ "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" }, the SPL Token program.
Find the Tatum Solana RPC endpoints and methods on Solana RPC.
NoteFind the official Solana documentation for the
getTokenAccountsByOwnerRPC method in the Solana docs.
FAQ
How do I get the balance of a single token account?
If you already know the token account address, call getTokenAccountBalance with it. It returns the balance of that one SPL Token account.
Can I use getProgramAccounts instead?
It isn't a reliable option for SPL tokens. getProgramAccounts scans every account the program owns, and RPC nodes can exclude programs with many accounts, such as Tokenkeg..., from it. See getProgramAccounts performance.
Still stuck?
Report the issue to support with the wallet address, the token mint and the dashboardLog ID from the error.
Updated 7 days ago