ERC20 Token Balances for a wallet

Hi,

If my goal is to get the token balances of several users on specified dates over a period what would be the best way to go about this?

For example: 100 users that I want to get weekly snapshot holdings for the last 12 months (or say monthly balance snapshots over the last 24 months)

One way I could do it is to request the tokens per wallet per month:
https://docs.moralis.io/web3-data-api/evm/reference/get-wallet-token-balances?
This means I would have to run this request 100 users x 52 weeks =5200 times, right?

Alternatively I could use the wallet history approach where I could request the complete wallet history: https://docs.moralis.io/web3-data-api/evm/reference/wallet-api/get-wallet-history?
Then recreate the wallet snapshots locally for the last 12 months.
This would only require 100 calls, right?

I was curious if there was a certain set of rules that could convert this second endpoint of wallet history to exactly match the snapshot of tokens from the first endpoint in every scenario.
Basically if i call the full wallet history of a user what would be the formula used to convert that wallet history to weekly snapshots.

Are there any exceptions in the wallet history that would give me an incomplete snapshot of a user for a given week or month?

Thank you.

Hi @Avo,

That’s correct, for weekly snapshots of 100 wallets on a complete year period, it would be approximately. 5200 reqs (per chain) in total. However, using the getWalletHistory endpoint you will be getting only the transactions/transfer/swap and other events of the wallet, you would then need to create your own logic to generate the balances from that data, which can be a much more complicated task v/s using the token balances endpoint directly.

If the team knows and can share what the logic would be to generate the balances from that data then that would greatly reduce the number of calls I would have to make and make it much easier.

If not, will resort to the token balances endpoint and just do more calls spaced out.

You could use the RPC node to get the balances but I don’t think that will reduce the number of calls. It will actually increase the API calls. You should also know which tokens the user wallet is holding before trying to fetch the token balance with nodes.

Sounds like RPC node would be worse off.

Best option sounds like either recreate the logic if team can’t share the specific logic or do thousands of calls.

Don’t want to send an inefficient series of requests to the server if there was another way.