0

Since it's not possible to get list of holders of specific ERC20 token using Solidity (due to non-iteratable mapping) I am looking for an API solution that would allow me to retrieve a list of holders (sorted by quantity and with limit parameter so I don't have to iterate through the whole list if I just need the largest holders) for a supplied ERC20 token address. I looked through some of the popular crypto API products in the market and could not find a solution but I know it's out there. I don't mind paying some reasonable pro subscription. I'd love for this solution to work across multiple EVM chains not just mainnet - Polygon, BSC, Avalanche, Optimism, Celo, Fantom, Arbitrum..

Is there an easy solution for this out there or I have to build my own by tracking past Transfer() events on each chain per token?

Thanks

mindbomb
  • 1,642
  • 4
  • 20
  • 35

3 Answers3

1

I don't think there are APIs that are build exclusively for smart contracts; however, you can go through this link.

Iterable Mapping

Yes we cannot iterate through mappings but we can do something like this.

And also refer to these answers.

How can we get token holders from token?

How do I check the number of token holders?

Tell me if it helps you!

Ad-h0c
  • 111
  • 2
  • Unfortunately that doesn't help - I can't use Iterable Mapping since the ERC20 contracts are already written and deployed obviously. The other suggestions talk about indexing Transfer() events which is possible but def not easy and does not provide an API access to sorted list of holders like Etherscan page does (currently I use web scraping but it's fragile and slow and inconsistent for different chains) – mindbomb Sep 12 '22 at 16:49
0

Somewhat unhelpful now, but this etherscan endpoint appears to do the trick - but you need a PRO plan.

etherscan docs

Thirdman
  • 21
  • 5
0

Yes we do Get holders of an erc20 token:

network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take MATIC token address as an example.

fetch(`https://api.chainbase.online/v1/token/holders?chain_id=${network_id}&contract_address=${token_addr}&page=1&limit=20`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));

I also have one blog about get a top holders of an erc20 account.