7

I want to get all details of blocks and transactions without using event logs. For example, I want to get a list of of transaction data which are sent to a specific contract.

  1. How can I parse local blockchain data?
  2. Where can I find the spec of blockchain data structure?

This is not about parsing the programming code.

1
  • 2
    @NikhilM don't think that's asking the same thing. This is asking about a blockchain parser, while that question asks about a Solidity/Serpent parser. Feb 19, 2016 at 7:01

3 Answers 3

9

GETH stores the downloaded blockchain as a levelDB key value database in the ~Ethereum/chaindata directory.

One possible approach is to use this Ethereum chain parser which will listen for Ethereum (block) chain events and turns them into MongoDB records. (Though it has not been updated in a while so it might not work)

Probably the easiest method is just to query via web3 like this explorer does. i.e Use web3.eth.blockNumber to get the latest block then for the last n blocks call web3.eth.getBlock then web3.eth.getTransaction

4

The data you're after are stored in a hash, which must be checked and validated as each successive block is added. The structure of each block is explained here, which has a nice illustration:

s
(source: ethereum.org)

The underlying data structure and hasing process are nicely explained here.

As you'll notice, there are no individual transactions anywhere in this block structure. Unless you want to iterate and merkle through the entire chain, you're much better off using getBlock and getTransaction as JackWinters suggested and then dumping the data you want into a database.

1

Like @JackWinters mentioned running a geth instance and querying is the easiest method.

But if you want to hold onto past block files in a static format that allows you to move it around easily and parse it while not actively running geth you can take a look at a tool I wrote. It will grab each block from your local geth instance and store it's data (including data on each of the transactions included in it) in a JSON file like this.

Your Answer

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

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