A single RPC call to return all token balances of a single user

We (Authereum) are looking for the best way to collect all token (and/or ETH) balances for a single address. This would look something like:

curl https://mainnet.infura.io \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"<custom_endpoint>_getTokenBalances","params": ["0xd0A7333587053A5BAe772BD37b9AAe724E367619"],"id":"42"}'

And would return:

  "result": {
    "address": "0xd0A7333587053A5BAe772BD37b9AAe724E367619"},
    "tokenBalances": [{"contractAddress": "0x6B175474E89094C44Da98b954EedeAC495271d0F", "tokenBalance": "0x0d06e87e858e", "error": null}, {"contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "tokenBalance": "0x8457abc736", "error": null}, {"contractAddress": "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643", "tokenBalance": "0xab27ba", "error": null}]

The call would get all token balances for 0xd0A7333587053A5BAe772BD37b9AAe724E367619 and return only addresses with a balance. Ideally it would return all ERC20 tokens and let us (the caller) parse the data for “spam” tokens.

Optionally, this could return the ETH balance as well, but that may not fit into this scope.

Hey @shane - thanks for the suggestion! MetaMask has achieved similar results for querying token balances by using this contract. There isn’t documentation for how their integration works, but it’s based off this DeltaBalances contract, which has extensive inline documentation. Hope this helps!

1 Like

Got it! Thank you.

We have seen that contract but are concerned about costs for polling frequently for a large number of users. I realize now that this would be no different than polling this new endpoint I requested as well.

Thank you for the feedback!