ethereumsoliditysmartcontractsethers.js

Collect holders of token (proxyble Contract)


I need to collect information about token holders.

Here is the token contract, it is proxy(bnb chain): 0x9356f6d95b8e109f4b7ce3e49d672967d3b48383

I see the use of the Mint method in it, but I don't see such a function in the implementation.

I decided to just take it through bscscan, try to find it manually through balanceOf on the implementation contract, but everything that is written in holders - says 0. So where and how should I get the information, I don't quite understand?

I had a plan like this:

  1. View the event (mint or transfer)
  2. write addresses from the event
  3. And then in the balanceOf function find out the number of tokens on them.

Where am I wrong here, and if I am right, then why doesn't it work?

So I'm trying to get list of holders and amount of holdings from token Contract.


Solution

  • Blockchain explorers (such as BSCScan) and other offchain apps often use indexers that work in this way:

    1. Loop through all Transfer event logs emitted by the token contract
    2. For each of the event logs, increase/decrease an offchain calculated balance of the recipient/sender.

    ad 2: Token mint and burn should emit the Transfer event as well. For mint the sender is address 0; and for burn - the recipient is address 0.


    Your approach is different by reading only the current balance at the time of the call to balanceOf(), which doesn't enable retrieving transaction history nor balance changes per address. And it can produce slightly inaccurate results if some of the balances change during the time you execute the set of calls to balaceOf().

    If you only want to retrieve current balances, your approach is valid.

    If you also need historical balances or list of transfers per address, you can use the approach described above.