What's the best way to get the list of token(ERC20) holders with their balance at a specific time? Thank you.
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 using
Build 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.
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.
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!