What's the best way to get the list of token(ERC20) holders with their balance at a specific time? Thank you.
4 Answers
ERC-20 tokens do not maintain an iterable list of current token holders, the used mapping type allows you only to check for a known address - balance. To get a list of all token holders, you need to process this offline and build it yourself from blockchain data.
I have created a standalone tool which collects ERC-20 token holders and transactions to SQLite database
Take a token contract address
Iterate over all
Transferevents for token usingeth_getLogsJSON-RPC APIBuild a local database of these events
Allow you to use SQL to query any account balance on any point of time (block num) by just running a
SUM()of account balances changes between blocks 1 - end block.
The core Python logic is here.
There are some quirks here and there: for example detecting mint / creation event for some tokens is not straightforward. Thus, you will may negative balance on the account receiving initial total supply if you rely on Transfer event only.
- 22,269
- 6
- 62
- 127
-
You can view the list of the particular token holders on etherscan under the Holders tab for example here https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7#balances. Also, if you view the Analytics tab for its contract you will find useful information for the balance during the contract's start date to present like here https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#analytics – mzaidi Feb 06 '20 at 06:57
-
Also, Etherscan offers balance checker tool. You can access it by going to contract -> more info (displayed on the right) -> select check previous balance by clicking on the 3 dots and then select the date for checking the balance. For example here https://etherscan.io/balancecheck-tool?a=0xB8c77482e45F1F44dE1745F52C74426C631bDD52. Hope that helps. – mzaidi Feb 06 '20 at 09:52
-
-
-
1Seems like the link broke (https://docs.tokenmarket.net/erc-20-holders.html). – merc1er Aug 29 '22 at 05:43
-
Try here https://github.com/miohtama/sto/blob/master/docs/source/captable.rst#cap-table-for-any-erc-20-token – Mikko Ohtamaa Aug 29 '22 at 07:20
This method does not always work, however it doesn't require writing code.
Go to the etherscan page of the token you want to get the token holders from. (ie https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7#balances)
Click on the little graph icon under the analytics column of the holders table.
The new page that pops up has a graph of the token balance over time. Check if it held the token at the specific time that you wanted.
This won't be too useful if the token has many holders, however, for tokens with less holders or if you just need one address that held the token at a specific time for testing, this works great!
- 61
- 1
Alternatively, you can use blockchain data APIs that have indexed data. Bitquery for example, has a token holder API that gives you the exact count and details of token holders at a point in time.
Examples:
- 31
- 4
I think the easiest way to get this done, is to use The Graph.
Then in a similar way to @mikko-ohtamaa's answer store the Transfer events.
You can get it done with no code, if using the graph as it will generate all code.
So in sort, follow their guide https://thegraph.com/docs/en/quick-start/
After the graph is deployed just do a simple graphQL query and done
- 121
- 5
Transferevents.) Getting the balance is just a matter of providing a block number with theeth_callcall. (I believe this is available viaweb3.jstoo.) – user19510 Jan 15 '18 at 01:30balanceOfon the token contract. – user19510 Jan 15 '18 at 01:32