<p>I wrote the Python script that can parse bitcoin raw dumps. There is no need of any modules or APIs, just Puthon 2.7 and blk00*.dat files. I hope it can help.</p>

<p><a href="https://github.com/normanvolt/blockchain-parser" rel="nofollow noreferrer">Blockchain parser</a></p>

CC BY-SA 4.0
2018-08-06T23:23:38.170Z
2018-08-06T23:58:26.397Z
2018-08-06T23:58:26.397Z
Denis Leonov
<p>To expand on Amaclin's answer you can look into JSON-RPC python wrappers such as python-bitcoinrpc which will allow you to make calls to your nodes database. With a fully synced node and <code>txindex=1</code> you can begin iterating through each block with for loops with <code>getblockhash</code> <code>getblock</code> <code>getrawtransaction</code> and <code>decoderawtransaction</code>. Yes, this will take a long time. </p>

CC BY-SA 3.0
2018-05-01T13:33:53.977Z
2018-05-01T13:33:53.977Z
m1xolyd1an
<p>Starting from this</p>

<blockquote>
  <p>Per espandere la risposta di Amaclin, puoi esaminare i wrapper Python JSON-RPC come python-bitcoinrpc che ti consentiranno di effettuare chiamate al database dei tuoi nodi. Con un nodo completamente sincronizzato e txindex=1puoi iniziare iterando attraverso ogni blocco con per i cicli con getblockhash getblock getrawtransactione decoderawtransaction. Sì, ci vorrà molto tempo.</p>
</blockquote>

<p>I had a similar problem, and in the beginning when bitcoin was dark for me, it led me slightly to think that the address data was contained within the transactions,
this thing is true but the address data with which to block the transactions are inside the scriptPubKey, only inside it therefore, to build a logical thread between these, besides having the reference to the current transaction, you must also have the reference to the output transaction that the input transaction refers to.</p>

<p>So in summary you have a transaction X and you want to decode your receiver, then access its data with the commands in the cited answer and using the command decodescript () with hexadecimal of the scriptPubKey you can get its id wallet.</p>

<p>But to get the data related to those satoshi, you must access the raw transaction contained in the Outpoint of the input transaction, perform the decoding and access the outuput transaction in position "n" (value contained within the outpoint) and execute the decodescript command of thePubKey script related to this output.</p>

<p>Only in this way can you reconstruct the public key inserted in the scirpt, and only by going back to the previous transaction linked to the current input transaction, can you execute a sort of chronology.</p>

<p>I want to add more information:
 - With these steps you may want to build an information graph to connect the wallet ids, well this is not enough, because with the P2SH scripts you can not expose the public key because you use a P2SH script address and therefore a wallet has potentiality endless addresses.</p>

<ul>
<li><p>This process is very slow, because it forces many queries on bitcoin
core, (it would speed up the thing using a parser of the blk files
and execute only the decoding of the scripts on it)</p></li>
<li><p>Once the addresses have been decoded, an analysis must be carried out
on which addresses are valid or not, keeping in mind that a
transaction of X satoshi to pay a sum </li>
</ul>

CC BY-SA 4.0
2019-08-26T10:00:18.730Z
2019-08-26T10:00:18.730Z
vincenzopalazzo
<p>I once used blockchain.info APIs in python for similar purpose, you can traverse with block height from 0 to latest with a python script.
And can write input and output addresses to a csv file. You can use 'set' to make sure there is no duplicates.</p>

<p>You will get response as json object. But it might be quite time consuming to fetch and read all the blocks and transactions. </p>

CC BY-SA 3.0
2017-09-10T14:20:03.090Z
Really slow, I have bitcoin-core up and running and I don't need blockchain.info APIs (network overhead) but still, bitcoin-core is slow too
I need to find a way to read blocks with levelDB one by one but I don't know how
John Kotkin
CC BY-SA 3.0
2017-09-10T16:31:57.793Z
I don't know much in the context then, can't help..
Piyush Chittara
CC BY-SA 3.0
2017-09-10T12:38:05.533Z
2017-09-10T12:38:05.533Z
Piyush Chittara
<p>I need to read all Bitcoin transactions from the first one until now and extract all Bitcoin addresses for further analyses</p>

<p>Any idea how to do it in Python?</p>

<bitcoin-core><python>
How to read each bitcoin block by python
John Kotkin
# How to read each bitcoin block by python

(Asked by: username_0 on 2017-09-10)

I need to read all Bitcoin transactions from the first one until now and extract all Bitcoin addresses for further analyses

Any idea how to do it in Python?

**Tags:** bitcoin-core, python


---

## 4 answers

### Answer by username_1 on 2018-08-06. Score: 2

I wrote the Python script that can parse bitcoin raw dumps. There is no need of any modules or APIs, just Puthon 2.7 and blk00\*.dat files. I hope it can help.

[Blockchain parser](https://github.com/normanvolt/blockchain-parser)


---

### Answer by username_2 on 2018-05-01. Score: 0

To expand on Amaclin's answer you can look into JSON-RPC python wrappers such as python-bitcoinrpc which will allow you to make calls to your nodes database. With a fully synced node and `txindex=1` you can begin iterating through each block with for loops with `getblockhash` `getblock` `getrawtransaction` and `decoderawtransaction`. Yes, this will take a long time.


---

### Answer by username_3 on 2019-08-26. Score: 0

Starting from this

> Per espandere la risposta di Amaclin, puoi esaminare i wrapper Python JSON-RPC come python-bitcoinrpc che ti consentiranno di effettuare chiamate al database dei tuoi nodi. Con un nodo completamente sincronizzato e txindex=1puoi iniziare iterando attraverso ogni blocco con per i cicli con getblockhash getblock getrawtransactione decoderawtransaction. Sì, ci vorrà molto tempo.

I had a similar problem, and in the beginning when bitcoin was dark for me, it led me slightly to think that the address data was contained within the transactions,
this thing is true but the address data with which to block the transactions are inside the scriptPubKey, only inside it therefore, to build a logical thread between these, besides having the reference to the current transaction, you must also have the reference to the output transaction that the input transaction refers to.

So in summary you have a transaction X and you want to decode your receiver, then access its data with the commands in the cited answer and using the command decodescript () with hexadecimal of the scriptPubKey you can get its id wallet.

But to get the data related to those satoshi, you must access the raw transaction contained in the Outpoint of the input transaction, perform the decoding and access the outuput transaction in position "n" (value contained within the outpoint) and execute the decodescript command of thePubKey script related to this output.

Only in this way can you reconstruct the public key inserted in the scirpt, and only by going back to the previous transaction linked to the current input transaction, can you execute a sort of chronology.

I want to add more information:
- With these steps you may want to build an information graph to connect the wallet ids, well this is not enough, because with the P2SH scripts you can not expose the public key because you use a P2SH script address and therefore a wallet has potentiality endless addresses.

* This process is very slow, because it forces many queries on bitcoin
  core, (it would speed up the thing using a parser of the blk files
  and execute only the decoding of the scripts on it)
* Once the addresses have been decoded, an analysis must be carried out
  on which addresses are valid or not, keeping in mind that a
  transaction of X satoshi to pay a sum


---

### Answer by username_4 on 2017-09-10. Score: 0

I once used blockchain.info APIs in python for similar purpose, you can traverse with block height from 0 to latest with a python script.
And can write input and output addresses to a csv file. You can use 'set' to make sure there is no duplicates.

You will get response as json object. But it might be quite time consuming to fetch and read all the blocks and transactions.

> **Comments:**
> **username_0**: Really slow, I have bitcoin-core up and running and I don't need blockchain.info APIs (network overhead) but still, bitcoin-core is slow too I need to find a way to read blocks with levelDB one by one but I don't know how  
> **username_4**: I don't know much in the context then, can't help..  

---

