I'm tasked with determining the current distribution and live wallet stats of a particular ERC20 token. My experience with Ethereum development is largely with web3js, and have a strong idea on how I would approach this challenge with web3js in a nodejs application and a datastore (likely mongodb/redis for speed)
First, I would execute an initial synchronization up the "current block" utilizing
web3.eth.filter watching the
transfer log of the token contract while also watching all current transfer events to continuously update wallet state on parties involved in a transfer.
The mechanics of the following approach could be achieved by linearly calculating balances which is more strait forward but requires perfect math and multi-step synchronization (synchronize to block height at sync start [result.args.blockNumber <= start_block], secondary sync from start_block to current, and then watch every block). The other more convoluted way would be to build an index of addresses representing token holders (past and present) and then mass querying wallet balance through
balanceOf() on several iterations that fix concurrency with each pass until it reaches acceptable margin-of-error, and finally having a watcher that updates balances for both token transaction parties. The former relies on linear calculation from start to finish whereas the latter relies on token contract balance state.
The first method is a bit easier in terms of development patterns and would by my likely choice, however, it seems to replicate the internal functionality of the contract which makes me wonder if I'm missing something entirely.
I've done a bit of research on this topic, but have come up empty handed. Maybe someone here has done something remotely similar and has some ideas on how to more efficiently acquire this data.
- An API that provides an export of distribution statistics for an ERC20 token
- An ERC20 centric library that simplifies this task
- A better way to aggregate this data with web3js
- Maybe better to use Python implementation of Web3?
I appreciate your time in reading this inquiry and any information you feel could help me in this journey.