I'm interested in analyzing the Bitcoin blockchain for occurrences of particular scripts and spending patterns. What are some good solutions for this? An ideal solution would let me filter transactions and outputs based on the contents of the locking and redeem scripts of single outputs as well as chains of outputs spending each other.

I've thought about looping over blocks and transactions with the Bitcoin Core RPC interface. This strikes me as probably not the most efficient solution, as I/O with bitcoind would probably be a bottleneck. Another solution would be to parse the raw block files, load them into memory (in a streaming fashion, as I don't have 200+ GB of memory...) and operate on them there. That sounds like a lot of work, so I was hoping there are some existing solutions for that out there.

3 Answers 3


It seems that bitcoin-iterate implements your second suggestion:

This is some fast code to iterate over bitcoind's block files to extract blockchain data from the main blockchain.

But as far as I know it doesn't allow your to filter by script. That would be a nice addition to the project, I think. Or you could write something similar that did that.

  • That seems really helpful! I'll probably need to add some code for transferring the hex scripts into op-codes. My C is a bit rusty (!), so I'll probably do that in a different language.
    – torkel
    Dec 10, 2019 at 8:57
  • bitcoin-cli decodescript does that. And it also works if the script is in the witness data (but if you apply it to witness data that isn't script you'll get the most bizarre results with opcodes never imagined and completely nonsensical).
    – fiatjaf
    Dec 10, 2019 at 15:19

I want to add my propose to this solution.

I have released the new parser called SpyCBlock, this is the simple parser blk file (multiprocessor).

With this parser is possible to serialize the blockchain into JSON, so blkxxxxx.dat -> blkxxxxx.json (also another type of serialization). I think with the JSON version is possible to run your analysis and I have run the simple analisis on the type of script used on the Bitcoin network, this is an example.

I think the version JSON is a propose to simplification the analysis of the bitcoin blockchain.


You may try blockchain-parser.

It converts raw blockchain data to the simple text files.

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