What is the structure of blk001.dat and blkindex.dat?

3

Can anyone tell me where I can read about the structure of the files

 blk0001.dat 
 blk0002.dat
 blkindex.dat

I know that in these files bitcoin is saving all the information about transactions. I would like to parse the files and save the information from these files in my local database.

[Note-these files are no longer used for Bitcoin-Qt/bitcoind version 0.8 and above.]

Salvador Dali

Posted 2012-10-07T15:02:49.060

Reputation: 3 050

Note - these files are no longer used in Bitcoin-Qt/bitcoind version 0.8 and above.Stephen Gornick 2013-03-07T08:18:48.947

1

Though those data files are BDB database files, the contents of blk000n.dat are simply raw concatenated bitcoin blocks: http://en.bitcoin.it/wiki/Data_directory So you are essentially asking what is the structure of the raw bitcoin blocks.

Stephen Gornick 2012-10-07T16:26:57.040

Answers

2

While reading the blockchain data directly is possible, you can only do so against stale data files -- as you can't reliably read the files while the client is running.

PyWallet and BitcoinTools are two such methods to do this.

Instead, the Bitcoin.org client (v0.7 and above) provides Raw Transactions support, in which you can decode a transaction to learn of its inputs, outputs and other attributes. This, along with the rest of the API provides the ability to pull all the data from the blockchain that is needed, against a live instance:

Stephen Gornick

Posted 2012-10-07T15:02:49.060

Reputation: 26 118