How can I retrieve the token balance of all the addresses used to store a spesific ERC20 token in Solidity?

That is, without having a list of addresses, but only relying on the data in the smart contract.


This is impossible to answer without knowing the code for the token you're interested in, but typically an ERC20 token stores balances in a mapping, which cannot be enumerated. That means there's no way from just the data in the smart contract to get a list of token holders.

Tools that do this sort of thing discover the addresses by observing events triggered by the contract instead.

  • Thank you for your answer. This would be from a contract that I developed myself, hence I would have all possibilites to make the proper function to do this. Is it still not possible to do directly? – andreasnico Mar 9 '18 at 19:39
  • 2
    Then you can just keep an array. – user19510 Mar 9 '18 at 23:55

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