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?

4 Answers 4


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


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.

  • 1
    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 Sep 10, 2017 at 14:20
  • I don't know much in the context then, can't help.. Sep 10, 2017 at 16:31

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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.