2

What is the best way to get all the token balances of an address? I Monitor the while blockchain and got Like 6k token contracts Stored. IS there any way to get all token balances of an address without having to call balanceOf of each of these contracts for the address? Like probably 5990 arent even held by a single address. Im wondering how to do that efficiently using web3

1 Answer 1

1

IS there any way to get all token balances of an address without having to call balanceOf of each of these contracts for the address?

Listen to all ERC-20 Transfer events to address.

Then from Transfer events check which were generated by valid token contracts.

Define your own criteria for "valid ERC-20 token."

5
  • if I listen to 5K token conracts Transfer events from block 0 to latest and store them in a database and from there generate address balances by adding and subtracting that would take me a huge amount of time for calculation and pulling data. Infura for example has a limit on getting past events per query.
    – Chris S
    Commented Jul 2, 2021 at 7:31
  • It does not matter how many contracts there are on the blockchain, because you are listening to a single event signature with one event handler. Commented Jul 2, 2021 at 11:04
  • If you are worried about API limits, run your own node: twitter.com/moo9000/status/1370323189486784513 Commented Jul 2, 2021 at 11:05
  • when I for example try to work with web3 getPastEvents("transfer") and I need them from block 0 to latest, i get an exception cause the query result is more than 10000. Im using Infura and their biggest subscription.
    – Chris S
    Commented Jul 2, 2021 at 11:45
  • Here, please read this web3py.readthedocs.io/en/stable/… Commented Jul 2, 2021 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.