1

I would like to fetch the list of all ETH wallet addresses by an API(?), given a smart contract address (erc20 token address).

Similar feature that we see on etherscan.io under the erc20 Holder list. Any docs/resource would be appreciated. Thanks

2
  • Please explain the relation between the input (an erc20 token contract address) and the output (a list of ETH wallet addresses). Commented Dec 23, 2020 at 19:38
  • essentially token holder list is the output given a token contract. etherscan.io holder list
    – dweepks
    Commented Dec 24, 2020 at 20:32

3 Answers 3

1

Your best bet would be via an API.

To get all the holders (some have limits) I would do this:

  1. Get all the transfers for the said token (all major api support this: alchemy, quicknode, etc... they have rate limit on free accounts tho)
  2. Store them in a json file or database so its easier to work with.
  3. Filter them by unique addresses

And if it is your erc20 contract (you createdd or you are the owner), you could just add something like that to do it:

contract MyContract is ERC20 {

   ... contract code ...

   uint256 private _holders;

   address[] private _allHolders;

   constructor() {

   ... existing code ...

   /// initialize the holders variable (new code)
   holders = 0;

   } 

   function mint(address _to, uint256 amt) { 

        ... code ...
        super._mint(_to, amt);
       _holders += 1; 
       _allHolders.push(_to);

   }

   /// that would be the function you call in your offchain code with web3.js or ether.js to get the count. 

   function holdersCount() public onlyOwner {
      return _holders   
   }

   function getAllHolders() public onlyOwner {
     return _allHolders;
   }

}
0

You can try Bloxy's Token API: https://bloxy.info/api_methods

I think the one you are looking for is "Token Holder List".

Some methods require a paid subscription but this one isn't.

0

It's not possible to get the holders information directly from the ERC20 contract itself.

However there are some services offering their API for querying such info. Covalent offers an API for free. Check the API reference for token holders endpoint here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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