Getting Web3 State Data
You too have been on Dune and looked for the Ethereum state data without being able to find it ? Well you're not alone, and we've been so frustrated with this that we've developed an in-house solution for it. If you want to learn how, let's go.
Let's head to our query editor and select Ethereum State from the data sources list.
The syntax to query for an event is specific to our platform, please respect it carefully. If you are like us and want to save time you can use the cool WEB3_STATE snippet by typing its name and selecting it from the list. It will give you a template of the info you need to fill in. Once we have it, let's input the information to track INV supply on mainnet using a read function.
Below is a query that retrieves the supply for INV token from its read function totalSupply() on the last 30 blocks :
We are here using relative block referencing, we've detailed a bit how it works in our article Getting Web3 Events, check it out. If you have already tried fetching for events, you can see here that the event_name has been replaced by function_name and that there is a lag argument.
If you don't specify for the blocks and lag, the system will return the value of the function call for the current ethereum state so at the last validated block. However, if you fill in the arguments as above, and hit 'Run Query' it will return you the following table :
As we can see, the query is returning for at every 1 block. For a larger number of block it can take time and we might not need all the information. If you want to capture a snapshot of these results with more blocks between each snapshot, you can increase the lag parameter.
For instance, a lag = 10000 will fetch data every 10,000 blocks over 1,000,000 blocks and will return you 100 lines of results.
If you need to perform more advanced calculation to your data, like giving a date to the block time or give the amount a proper decimal, you might want to take a look at our doc : Querying Existing Query Results and use the result of the query we just designed as a datasource using our SQLite client.
Have fun on inverse.watch !