I want to get token holding of an address with web3.js. If I have an address, 0x00000.....123 is there a way I can get all the tokens that address hold, like etherscan shows the tokens and balances.

I think we can do this other way around, by getting token contract address and ask for balanceOf(address), but that will be a lengthy process, and I need to know tokens contract address beforehand.

Thanks for the help.


Since the balance of a user is only stored in the contract of the token, the only way to get the balances is to query the token address. You'd either have to use an API like Etherscan's to get a list of token addresses, or scan the blockchain yourself to find contracts that look like ERC20 tokens and compile a list to then get the balances of the user on each contract.

Not the answer you're looking for? Browse other questions tagged or ask your own question.