[Ethereum] How to read block data from chaindata

blockchainleveldb

I know that chaindata folder (on Mac OS X) stores the state as key/value database. But how is a block stored? Are transactions also stored as key/value pairs? If yes, how to identify which files belong to transactions and which files belong to state? I have a bunch of levelDB files 'ldb' under chaindata and I have no idea how to probe them, say using python levelDB bindings.

This question does ask a bit about the blockchain, however the answer does not particularly refer to how blocks are stored.

EDIT: I am concerned with low-level representation of transactions and blocks and how they are stored on disk. I understand that they are in RLP format from ethereum wiki. What exactly I am looking for is which files belong to blocks (and transactions) and which don't.

Best Answer

The easiest way is to use the official NodeJS library, write a few lines of JavaScript to scan all of the blocks, and optionally all transactions in each block. Start at block 0 and keep scanning until it returns null.

You can do that with far less code than it would take to read/parse, and it would have the added benefit of never needing an upgrade just because the underlying db changed.

Related Topic