<p>The best way to write a parser of your own for the blockchain is to find the source code of one that already exists and from that deduce the precise underlying data structure and how to parse and interpret it.  e.g. <a href="https://code.google.com/p/blockchain/source/browse/trunk/BlockChain.h" rel="noreferrer">here</a> in C++ and <a href="https://github.com/mb300sd/Bitcoin-Tool/tree/master/Bitcoin%20Tool/Structs" rel="noreferrer">here</a> in C# - and there are many others.</p>

<p>The data in the blockchain is stored in a <a href="https://en.bitcoin.it/wiki/Protocol_specification" rel="noreferrer">custom binary format</a> that is a little tricky to untangle without some help; <a href="http://2.bp.blogspot.com/-DaJcdsyqQSs/UsiTXNHP-0I/AAAAAAAATC0/kiFRowh-J18/s1600/blockchain.png" rel="noreferrer">this link</a> seems as good as any to get started on the overall structure.</p>

<p>There are many"gotcha's" to watch out for.  For example: </p>

<ul>
<li><a href="http://en.wikipedia.org/wiki/Endianness" rel="noreferrer">'endianess'</a> i.e. having to reverse binary digits before interpretation and </li>
<li>some of the interesting values associated with a transaction have to be calculated e.g. for <a href="https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses" rel="noreferrer">addresses</a></li>
<li><a href="http://php.net/manual/en/book.bc.php" rel="noreferrer">'big numbers'</a> where the numbers used internally are so huge you may need custom code/libraries to deal with them</li>
</ul>

<p>Comparing your results to those that are freely available via the <a href="https://blockchain.info/" rel="noreferrer">blockchain</a> and <a href="https://blockexplorer.com/" rel="noreferrer">blockexplorer</a> as well as the <a href="https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29" rel="noreferrer">bitcoind.exe API</a> would be a must.  Otherwise it is easy to pull out seemingly valid transactions that are just nonsense.  I speak from experience.</p>

<p>While writing your own parser for the blockchain is a worthwhile learning exercise you would be much better off IMHO using the bitcoin API and ignoring the underlying blockchain database for any 'real' code.</p>

CC BY-SA 3.0
2014-10-04T12:07:01.967Z
2014-10-04T12:07:01.967Z
Fred Tingey
<p>The best way to access transaction database for analysis is probably through the <a href="http://blockchain.info/q" rel="nofollow">blockchain.info API</a>. You can also use the <a href="http://blockexplorer.com" rel="nofollow">Bitcoin Block Explorer</a>; in fact, this is what a study of the Bitcoin network did.</p>

CC BY-SA 3.0
2013-05-29T22:53:52.840Z
2013-05-29T22:53:52.840Z
katriel
<p>The easiest way is to use my <a href="https://github.com/ragestack/blockchain-parser" rel="nofollow noreferrer">blockchain parser</a>. This script can parse all the data from blk*****.dat files into the human readable text view. </p>

<p><a href="https://i.sstatic.net/5GZ7K.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5GZ7K.jpg" alt="blockchain parser"></a></p>

CC BY-SA 4.0
2020-02-29T11:23:25.420Z
2020-02-29T11:23:25.420Z
Denis Leonov
<p>I want to process the Bitcoin network's transactions. As I understand it, the Bitcoin-Qt client downloads and stores all that information locally. </p>

<p>Since version 0.8 LevelDB has been used to access this data. I found two databases, in <em>blocks/index</em> and in <em>chainstate</em>. However, I cannot make sense of the content. The first entry looks like this:</p>

<pre><code>B = ??????{?:???????`?5g??
</code></pre>

<p>Am I on the right track and where can I find a specification of the data?</p>

CC BY-SA 3.0
2013-07-29T07:17:48.337Z
The data is stored in an application-specific format optimized for compact storage, and wasn't really intended to be easily parsed by other applications. You can access the data in the chainstate through the `gettxout` RPC call, and the data in the block index through `getblock`. I'll try to find time for a write-up of the exact format.
Pieter Wuille
CC BY-SA 3.0
2014-10-03T10:47:26.873Z
@PieterWuille Your comment would be a great start for an answer.
Murch
<blockchain><bitcoin-core><leveldb>
How to access Bitcoin's transaction database?
msteiger
# How to access Bitcoin's transaction database?

(Asked by: username_0 on 2013-04-19)

I want to process the Bitcoin network's transactions. As I understand it, the Bitcoin-Qt client downloads and stores all that information locally. 
Since version 0.8 LevelDB has been used to access this data. I found two databases, in blocks/index and in chainstate. However, I cannot make sense of the content. The first entry looks like this:
B = ??????{?:???????`?5g??

Am I on the right track and where can I find a specification of the data?

**Tags:** blockchain, bitcoin-core, leveldb

> **Comments:**
> **username_1**: The data is stored in an application-specific format optimized for compact storage, and wasn't really intended to be easily parsed by other applications. You can access the data in the chainstate through the `gettxout` RPC call, and the data in the block index through `getblock`. I'll try to find time for a write-up of the exact format.  
> **username_2**: @PieterWuille Your comment would be a great start for an answer.  

---

## 3 answers

### Answer by username_3 on 2014-10-04. Score: 6

The best way to write a parser of your own for the blockchain is to find the source code of one that already exists and from that deduce the precise underlying data structure and how to parse and interpret it. e.g. [here](https://code.google.com/p/blockchain/source/browse/trunk/BlockChain.h) in C++ and [here](https://github.com/mb300sd/Bitcoin-Tool/tree/master/Bitcoin%20Tool/Structs) in C# - and there are many others.

The data in the blockchain is stored in a [custom binary format](https://en.bitcoin.it/wiki/Protocol_specification) that is a little tricky to untangle without some help; [this link](http://2.bp.blogspot.com/-DaJcdsyqQSs/UsiTXNHP-0I/AAAAAAAATC0/kiFRowh-J18/s1600/blockchain.png) seems as good as any to get started on the overall structure.

There are many"gotcha's" to watch out for. For example:

* ['endianess'](http://en.wikipedia.org/wiki/Endianness) i.e. having to reverse binary digits before interpretation and
* some of the interesting values associated with a transaction have to be calculated e.g. for [addresses](https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses)
* ['big numbers'](http://php.net/manual/en/book.bc.php) where the numbers used internally are so huge you may need custom code/libraries to deal with them

Comparing your results to those that are freely available via the [blockchain](https://blockchain.info/) and [blockexplorer](https://blockexplorer.com/) as well as the [bitcoind.exe API](https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29) would be a must. Otherwise it is easy to pull out seemingly valid transactions that are just nonsense. I speak from experience.

While writing your own parser for the blockchain is a worthwhile learning exercise you would be much better off IMHO using the bitcoin API and ignoring the underlying blockchain database for any 'real' code.


---

### Answer by username_4 on 2013-05-29. Score: 2

The best way to access transaction database for analysis is probably through the [blockchain.info API](http://blockchain.info/q). You can also use the [Bitcoin Block Explorer](http://blockexplorer.com); in fact, this is what a study of the Bitcoin network did.


---

### Answer by username_5 on 2020-02-29. Score: 1

The easiest way is to use my [blockchain parser](https://github.com/ragestack/blockchain-parser). This script can parse all the data from blk\*\*\*\*\*.dat files into the human readable text view.

[![blockchain parser](https://i.sstatic.net/5GZ7K.jpg)](https://i.sstatic.net/5GZ7K.jpg)


---

