3

On etherscan, the View Tokens dropdown in the Token Trackr section lists how many different ERC20 tokens that address has and the quantity, how is this done?

TylerH
  • 20,799
  • 66
  • 75
  • 101
totalnoob
  • 2,521
  • 8
  • 35
  • 69
  • Refer to this [answer](https://stackoverflow.com/a/50019666/6521116) of [Send ERC20 token with web3](https://stackoverflow.com/q/48180941/6521116) – LF00 Apr 25 '18 at 12:59

1 Answers1

1

They probably just collect data from the blockchain in their own database and collate it to user friendly UI.

Using web3.js, you have to do this manually for every token like this:

var MyContract = web3.eth.contract(abiArray);

// instantiate by address
var contractInstance = MyContract.at(address);

contractInstance.balanceOf(my_address, function(error, success){
   if(error) console.log ("Something went wrong: " + error);
   else console.log ("Balance: " + success.toString(10)); 
});
TylerH
  • 20,799
  • 66
  • 75
  • 101
Roman Frolov
  • 998
  • 11
  • 18
  • what are they using to collect information from the blockchain with? – totalnoob Feb 21 '18 at 19:18
  • @totalnoob they just have their own nodes with Ethereum client like geth. – Roman Frolov Feb 21 '18 at 19:21
  • ahh, mybad. I meant using web3, not solidity. changed the title – totalnoob Feb 21 '18 at 19:32
  • @totalnoob you simply need to get token address and abi. After that you will have all the interface of the ERC20 token you need to call `contractInstance.balanceOf(my_address)`. – Roman Frolov Feb 21 '18 at 19:37
  • I would recommend you my library https://www.npmjs.com/package/erc20-contract-js - Simple JS library used to manipulate with ERC-20 token contracts. To receive token balance of multiple ERC20 token, all you need is to create one instance of ERC20Contract for each token, and then call function balnaceOf. – Osoian Marcel Feb 27 '18 at 12:57