How to Get a List of Tokens Held by an Ethereum Address

addressesetheretherscantokens

TL;DR: wanted: a method that receives an address as a parameter and returns an array of token names/contracts/balances held by address.

I'm aware of the fact that Etherscan API has a method allowing you to see the balance of an address, when you supply the contract taddress of a token. My question is: how do I get a list of tokens an address hold?

Case in point: when you go to Etherscan, there's a dropdown, showing a list of tokens and balances. Surely it is not the case (I hope) that Etherscan iterates through all known token contracts to look for the address?

How can I build such a list?

Best Answer

That's exactly what Etherscan does - they have a list of tokens that they track. You'll then have to do a balanceOf query on each token with the address you want to get balance for.

There is no central repository of token balances, since they are all their own individual contracts that just contain user balances.

Edit: If you're querying balances directly from the chain, you can also use this balance checker library. You can query the contract directly here. Just pass a list of accounts and tokens and it will automatically return the list of the balances for each account on each token with one API call.

Related Topic