<blockquote>
  <p>But how to parse those files?</p>
</blockquote>

<p>It is not too difficult to parse bitcoin blockchain if you have programming skills and know what you want to do. Have a look to my piece of code - this is just a working example that parsing is easy. Of course, you have to write code in your favorite language for your task</p>

<pre><code>#include &lt;QTimer&gt;

#include "BlockChain.h"
#include "Util.h"
#include "MyByteArray.h"
#include "Target.h"

BlockChain::BlockChain ( QObject* parent ) : QFile ( parent ), blkFile ( START_BLOCK )
{
  connect ( this, SIGNAL ( block ( const QByteArray&amp; ) ), parent, SLOT ( block ( const QByteArray&amp; ) ) );
  connect ( this, SIGNAL ( doneFile ( ) ), parent, SLOT ( doneFile ( ) ) );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

void BlockChain::start ( )
{
  setFileName ( blkFileName ( blkFile++ ) );
  if ( !open ( QIODevice::ReadOnly ) )
  {
    _trace ( QString ( "cant open [%1]" ).arg ( fileName ( ) ) )
    emit block ( QByteArray ( ) );
    deleteLater ( );
  }
  else
  {
    _trace ( QString ( "processing [%1]" ).arg ( fileName ( ) ) )
    QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
  }
}

void BlockChain::next ( )
{
  if ( pos ( ) &lt; size ( ) )
  {
    quint32 magic;
    quint32 sz ( read ( (char*)&amp;magic, 4 ) );
    while ( !magic &amp;&amp; pos ( ) &lt; size ( ) - 4 )
      read ( (char*)&amp;magic, 4 );
    xassert ( ( ( magic == MAGIC_ID ) || !magic ) &amp;&amp; ( sz == 4 ) )
    if ( magic )
    {
      read ( (char*)&amp;sz, 4 );
      emit block ( read ( sz ) );
      QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
      return;
    }
  }
  close ( );
  emit doneFile ( );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

const QString BlockChain::blkFileName ( const int i ) const
{
  return
    ( i &lt; 10 ) ? QString ( DATA_ROOT "\\blk0000%1.dat" ).arg ( i ) :
    ( i &lt; 100 ) ? QString ( DATA_ROOT "\\blk000%1.dat" ).arg ( i ) :
    ( i &lt; 1000 ) ? QString ( DATA_ROOT "\\blk00%1.dat" ).arg ( i ) :
    QString ( DATA_ROOT "\\blk0%1.dat" ).arg ( i );
}
</code></pre>

CC BY-SA 4.0
2023-03-16T09:01:21.563Z
Which library is this?
ManuelSchneid3r
CC BY-SA 4.0
2019-02-06T05:18:43.113Z
2019-02-06T05:18:43.113Z
amaclin
<p>Python 3 parser available here <a href="https://github.com/alecalve/python-bitcoin-blockchain-parser" rel="nofollow noreferrer">https://github.com/alecalve/python-bitcoin-blockchain-parser</a></p>

CC BY-SA 4.0
2020-01-16T16:52:01.770Z
2020-01-16T16:52:01.770Z
evandrix
<p>The easiest way is to use my simple python script (<a href="https://github.com/ragestack/blockchain-parser" rel="nofollow noreferrer">blockchain parser</a>) that can parse whole raw data from the blk*****.dat files into the human readable text view. This script is very simple to understand and it would be the best way to find out what hiding behind the blockchain database.</p>

CC BY-SA 4.0
2019-10-01T14:20:49.437Z
2019-10-01T14:20:49.437Z
Denis Leonov
<p>I want to update the status of the Bitcoin parser projects, one month ago I have released the new Bitcoin parser caller SpyCBlock, it resides to github at <a href="https://github.com/vincenzopalazzo/SpyCblock" rel="nofollow noreferrer">this link</a>.</p>

<p>SpyCBlock is a simple parser multicore written with C++11, it parsing the file blk****.dat and produce different serialization, like:</p>

<ul>
<li>Serialization JSON Bitcoin blockchain.</li>
<li>Serialization Graph of transaction.</li>
<li>Serialization Graph of address (With version Bitcoin core &lt;= 18.1)</li>
</ul>

<p>You can see the demo graph with this <a href="https://github.com/vincenzopalazzo/SpyJSBlock.react" rel="nofollow noreferrer">web application</a>.</p>

<p>Also, the very cool stuff is the JSON bitcoin blockchain because you can analyze it easier with your preferer language.</p>

<p>an example, with a Python demo I have to analyze the type of script used in Bitcoin blockchain, this is the result</p>

<p><a href="https://i.sstatic.net/lkNEH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lkNEH.png" alt="enter image description here"></a></p>

<p>also, you can see the result <a href="https://github.com/vincenzopalazzo/AnalyticsPyBlock/deployments" rel="nofollow noreferrer">here</a> too.</p>

<p>The demo analytics called AnalyticsPyBlock, written in Python3 and reside in Github ad this link <a href="https://github.com/vincenzopalazzo/AnalyticsPyBlock" rel="nofollow noreferrer">https://github.com/vincenzopalazzo/AnalyticsPyBlock</a></p>

CC BY-SA 4.0
2020-01-18T12:48:51.557Z
2020-01-18T12:48:51.557Z
vincenzopalazzo
<p>The easiest way to parse the blockchain is to use the built-in JSON-RPC API instead of trying to get data directly from blk*.dat files. The official documentation is available here: <a href="https://bitcoin.org/en/developer-reference#bitcoin-core-apis" rel="nofollow noreferrer">https://bitcoin.org/en/developer-reference#bitcoin-core-apis</a></p>

CC BY-SA 4.0
2019-02-07T16:50:45.283Z
2019-02-07T16:50:45.283Z
Blockchair
<p>I'm a freshman of bitcoin system and I'm trying to find out how to use bitcoin parser. I downloaded several from internet but they were not work out. Currently I am using Bitcoin Knots wallet and downloaded all blockchains (approx.223GB). I know those data are preserved in the file names blockchain and they are in the form like blk0xxxx.dat. But how to parse those files? I really want to know the answer!</p>

<blockchain><bitcoin-knots>
wondering How to use Bitcoin Parser?
Tony642
# wondering How to use Bitcoin Parser?

(Asked by: username_0 on 2019-02-06)

I'm a freshman of bitcoin system and I'm trying to find out how to use bitcoin parser. I downloaded several from internet but they were not work out. Currently I am using Bitcoin Knots wallet and downloaded all blockchains (approx.223GB). I know those data are preserved in the file names blockchain and they are in the form like blk0xxxx.dat. But how to parse those files? I really want to know the answer!

**Tags:** blockchain, bitcoin-knots


---

## 5 answers

### Answer by username_1 on 2019-02-06. Score: 3

> But how to parse those files?

It is not too difficult to parse bitcoin blockchain if you have programming skills and know what you want to do. Have a look to my piece of code - this is just a working example that parsing is easy. Of course, you have to write code in your favorite language for your task

```
#include <QTimer>

#include "BlockChain.h"
#include "Util.h"
#include "MyByteArray.h"
#include "Target.h"

BlockChain::BlockChain ( QObject* parent ) : QFile ( parent ), blkFile ( START_BLOCK )
{
  connect ( this, SIGNAL ( block ( const QByteArray& ) ), parent, SLOT ( block ( const QByteArray& ) ) );
  connect ( this, SIGNAL ( doneFile ( ) ), parent, SLOT ( doneFile ( ) ) );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

void BlockChain::start ( )
{
  setFileName ( blkFileName ( blkFile++ ) );
  if ( !open ( QIODevice::ReadOnly ) )
  {
    _trace ( QString ( "cant open [%1]" ).arg ( fileName ( ) ) )
    emit block ( QByteArray ( ) );
    deleteLater ( );
  }
  else
  {
    _trace ( QString ( "processing [%1]" ).arg ( fileName ( ) ) )
    QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
  }
}

void BlockChain::next ( )
{
  if ( pos ( ) < size ( ) )
  {
    quint32 magic;
    quint32 sz ( read ( (char*)&magic, 4 ) );
    while ( !magic && pos ( ) < size ( ) - 4 )
      read ( (char*)&magic, 4 );
    xassert ( ( ( magic == MAGIC_ID ) || !magic ) && ( sz == 4 ) )
    if ( magic )
    {
      read ( (char*)&sz, 4 );
      emit block ( read ( sz ) );
      QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
      return;
    }
  }
  close ( );
  emit doneFile ( );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

const QString BlockChain::blkFileName ( const int i ) const
{
  return
    ( i < 10 ) ? QString ( DATA_ROOT "\\blk0000%1.dat" ).arg ( i ) :
    ( i < 100 ) ? QString ( DATA_ROOT "\\blk000%1.dat" ).arg ( i ) :
    ( i < 1000 ) ? QString ( DATA_ROOT "\\blk00%1.dat" ).arg ( i ) :
    QString ( DATA_ROOT "\\blk0%1.dat" ).arg ( i );
}

```

> **Comments:**
> **username_2**: Which library is this?  

---

### Answer by username_3 on 2020-01-16. Score: 2

Python 3 parser available here <https://github.com/alecalve/python-bitcoin-blockchain-parser>


---

### Answer by username_4 on 2019-10-01. Score: 1

The easiest way is to use my simple python script ([blockchain parser](https://github.com/ragestack/blockchain-parser)) that can parse whole raw data from the blk\*\*\*\*\*.dat files into the human readable text view. This script is very simple to understand and it would be the best way to find out what hiding behind the blockchain database.


---

### Answer by username_5 on 2020-01-18. Score: 0

I want to update the status of the Bitcoin parser projects, one month ago I have released the new Bitcoin parser caller SpyCBlock, it resides to github at [this link](https://github.com/username_5/SpyCblock).

SpyCBlock is a simple parser multicore written with C++11, it parsing the file blk\*\*\*\*.dat and produce different serialization, like:

* Serialization JSON Bitcoin blockchain.
* Serialization Graph of transaction.
* Serialization Graph of address (With version Bitcoin core <= 18.1)

You can see the demo graph with this [web application](https://github.com/username_5/SpyJSBlock.react).

Also, the very cool stuff is the JSON bitcoin blockchain because you can analyze it easier with your preferer language.

an example, with a Python demo I have to analyze the type of script used in Bitcoin blockchain, this is the result

[![enter image description here](https://i.sstatic.net/lkNEH.png)](https://i.sstatic.net/lkNEH.png)

also, you can see the result [here](https://github.com/username_5/AnalyticsPyBlock/deployments) too.

The demo analytics called AnalyticsPyBlock, written in Python3 and reside in Github ad this link <https://github.com/username_5/AnalyticsPyBlock>


---

### Answer by username_6 on 2019-02-07. Score: -1

The easiest way to parse the blockchain is to use the built-in JSON-RPC API instead of trying to get data directly from blk\*.dat files. The official documentation is available here: <https://bitcoin.org/en/developer-reference#bitcoin-core-apis>


---

