forEveryChain

Thomas Jay Rush
4 min readFeb 2, 2022

Come Visit with Us for a While

Have you ever had the desire to look at every trace of every transaction of every block on every blockchain? Yes? Well, pull up a chair.

It’s a Multi-Chain World

I’m sure you’re all aware of the impending multi-chain universe. You know the one. Where all sorts of little baby communities of people are going to be doing all sorts of little baby community-like things. Charities over here. Games down here. Ultra sophisticated blockchain finance application up there.

If you know me, you know I’m a decentralization maximalist. That’s why it’s always perplexed me how the above multi-chain world can possibly ever remain decentralized.

This week we took a stab at answering that question by adding a new feature to TrueBlocks that we call multi-chain support. This feature seems relatively simple on its face — a user only has to add --chain <whatever> to his/her chifra command lines — but it opens up a whole new world of possibilities (and headaches) — and…

IT WORKS ON A DESKTOP (← this should be our new logo!)

In this article, I want to show you an example of one of the new possibilities.

I’ll start by explaining an existing bit of example code from the TrueBlocks repo called forEveryTrace.

This example visits every block in the Ethereum Mainnet, and from there every transaction in every block, and finally every trace in every transaction in every block.

I’ll conclude the article by talking about a new peice of code called forEveryChain which came into existance literally ten minutes ago and inspired this post.

forEveryTrace

We assume a certain amount of familiarity with TrueBlocks in particular how to install it and get it running. We also assume you have access to your own node software. We highly recommend Erigon running locally, and while the following code will work with Infura, you will defintely get rate limited. Don’t say we didn’t warn you.

In our repo there’s a folder called ./examples and in that folder, there’s an example called ./forEvery. Here’s the contents of the code in the folder:

Source code for forEveryTrace

If you’re familiar with C++ code at all, you’ll notice the main function at line 34 is really simple. Initialize the library, call a single function, and clean up.

While simple, that one function packs a wallop. It does exactly as it says, it visits every block in the entire blockchain it’s configured for. (By default this means Ethereum Mainnet, but we’ll get back to this in a minute.)

What line 38 does is:

For every block in the current blockchain, call the function visitBlock (line 29) and pass it a pointer to counter.

What does the visitBlock function do?

For every transaction in the current block, call the function visitTransaction (line 24) passing in the same pointer.

What does the function visitTransaction do?

For every trace in the current transaction call the function visitTrace (line 16) passing in the same pointer.

And finally, what does visitTrace do?

It keeps a count of the total number of traces in the entire blockchain and prints out each trace.

An Aside on the Concept of ON THE DESKTOP

If you look carefully at this code, you’ll understand a little bit of why TrueBlocks still works on the desktop even after more than 14,000,000 Mainnet blocks.

We’re not extracting any permanent data from the chain.

While TrueBlocks provides for a binary cache that speeds up processing many times over raw node queries, the cache is optional. The cache is only employed if the end-user instructs us to use the cache.

We leave the decision of whether or not to cache to you. This is markedly different from any other solution we’re aware of and it’s why we still work on a desktop.

If you want to cache the entire blockchain because that’s your requirement — the first thing you have to do is get a really, really large hard drive — and then alter the above code to write each block, transaction, or trace to either our cache or your database.

This is the exact problem we have with solutions such as Amber Data and EtherScan. They’ve chosen to extract and cache every single piece of data on the entire blockchain prior to the developer’s decision if it’s pertinent. This creates many, many Terabytes of data which means their solutions will never work on a desktop and therefore will never be truly decentralized. Enough soapbox — back to the point.

For Every Trace on Any Chain in the Visible Universe

As I mentioned above, this week we added a multi-chain feature to TrueBlocks which means we can process queries for any EVM-based blockchain with the same equal ease as we process Mainnet.

I was inspired to write this post because I thought of the following modification to the above example.

What does this actually do?

It visits every trace in every transaction in every block on any EVM-based blockchain ON A FUCKING DESKTOP.

Support Our Work

TrueBlocks is self-funded from our own personal funds and grants from our supporters including The Etheruem Foundation (2018), Consensys (2019), Moloch DAO (2021), and most recently Filecoin/IPFS (2021).

And you!

If you like this article and wish to support please donate to our GitCoin grant https://gitcoin.co/grants/184/trueblocks. Donate during the next matching round, and we get the added benefit of the matching grants. Even small amounts have a big impact.

If you’d rather, feel free to send ETH or any other token to us directly at trueblocks.eth or 0xf503017d7baf7fbc0fff7492b751025c6a78179b.

--

--

Thomas Jay Rush

Blockchain Enthusiast, Founder TrueBlocks, LLC and Philadelphia Ethereum Meetup, MS Computer Science UPenn