Search code examples
ethereumetherscan

How to get Ethereum token holders amount history and analysis daily


I wanna to create a chart diagram for analysis token holders amount history, for example:

holders amount

  ▲
  │              ┌─────
  │              │
  │              │
  │              │
  │       ┌──────┘
  │       │
  │       │
  │ ┌─────┘
  │ │
  │ │
  └─┴───────────────────►  date

X axis is for date, Y axis is for holders amount, above chart is meaning that holders amount is increase over date.

However the problem is that I can't get the holders amount in the past date, The etherscan only provide a real-time holders amount.


Solution

  • You can calculate the total amount of token holders in time from the Transfer() event logs.

    Use the getPastLogs() web3 function for example to collect the historical event logs.

    • from the block when the token contract was deployed

    • to the latest (curent) block or whichever suits your needs

    • address of the token contract emiting these event logs

    • topics help you to filter only some events, or only events containing a specific value

      For example in your case, the Transfer(address,address,uint256) event results in the value ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef (keccak-256 hash of the event signature) of the topics[0] item. So you can chose to filter only logs of this event - and not approvals, and other events.