Monthly Token Balances
Can I create a list of token balances by month?
Posted January 6, 2023 ‐ 1 min readtags: [ Tutorials ]
A TrueBlocks recipe to show ERC 20 token balances for an address.
Note: The following assumes you have a copy of (either by having built it yourself or downloaded it) the TrueBlocks Appearance Index.
We start by extracting from the chain all the transactions for the address in question. We will use a randomly selected address that we know owns a number of different tokens.
chifra list 0x03fdcadc09559262f40f5ea61c720278264eb1da
This produces a list of 2,129 appearances (at the time of this writing). Each appearances is a pair of integers detailing the blockNumber and transactionIndex of the transaction. Note that other methods of getting such a list (such as EtherScan APIs) return far fewer transactions. We will explain this in a later post.
One user asked if it was possible to run TrueBlocks against multiple RPC endpoints at the same time. This is short recipe to accomplish just that.
The first thing to understand is that the TrueBlocks core runs against a local configuration file stored in your $HOME folder called $HOME/.local/share/TrueBlocks/trueBlocks.toml. It’s an almost ridiculously simple file.
The file gets created and populated with default values the first time you build TrueBlocks. When you do cmake ../src and then make in the build folder of the TrueBlocks repo, you can look inside the file $HOME/.local/share/trueblocks/trueBlocks.toml.
A TrueBlocks recipe to show every ERC20 Transfer event from a given smart contract.
Note: The following assumes you have a copy of (either by having built it yourself or downloaded it) the TrueBlocks Appearance Index. These instructions also assume that the address you’re querying is an ERC 20 smart contract.
To get started, we want to extract (from the TrueBlocks index) a list of every transaction that our address has ever appeared in.