ethereumcryptocurrencyerc20etherscan

How to find erc20 tokens balance


I'm trying to find the balance of ERC20 tokens (such as Tether) of specific addresses.

Actually, I hope to find an API that works like below, get the account address and contract address and return the balance of that specific token.

Ether Scan token check

To clarify my purpose, in the TRC20 network, I use this endpoint and there is an array of TRC20 token balances in the response.


Solution

  • In Ethereum there is no built-in API like Trongrid to retrieve the balance of tokens of certain accounts.

    If you want to do this, you have to call "balanceOf" method of smart contract tokens.

    Infura APIs have an eth_call method to do this.

    Calling this API is a little tricky, I wrote two code snippets for this reason, in JS and Go.

    JS: https://gist.github.com/arshamalh/33e6646eb793997f2cc69668bd97010a

    Go: https://gist.github.com/arshamalh/9fe035f7fe18cb5387737546ef84bf6c