<p>It seems that <a href="https://github.com/rustyrussell/bitcoin-iterate" rel="nofollow noreferrer">bitcoin-iterate</a> implements your second suggestion:</p>

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

<p>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.</p>

CC BY-SA 4.0
2019-12-10T08:57:19.233Z
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
CC BY-SA 4.0
2019-12-10T15:19:43.570Z
`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
CC BY-SA 4.0
2019-12-09T21:17:31.453Z
2019-12-09T21:17:31.453Z
fiatjaf
<p>I want to add my propose to this solution.</p>

<p>I have released the new parser called <a href="https://vincenzopalazzo.github.io/SpyCblock/" rel="nofollow noreferrer">SpyCBlock</a>, this is the simple parser blk file (multiprocessor).</p>

<p>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, <a href="https://vincenzopalazzo.github.io/AnalyticsPyBlock/" rel="nofollow noreferrer">this is an example</a>.</p>

<p>I think the version JSON is a propose to simplification the analysis of the bitcoin blockchain.</p>

CC BY-SA 4.0
2019-12-13T19:40:49.453Z
2019-12-13T19:40:49.453Z
vincenzopalazzo
<p>You may try <a href="https://github.com/ragestack/blockchain-parser" rel="nofollow noreferrer">blockchain-parser</a>.</p>

<p>It converts raw blockchain data to the simple text files.</p>

CC BY-SA 4.0
2019-12-10T08:50:54.423Z
2019-12-10T08:50:54.423Z
Denis Leonov
<p>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. </p>

<p>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 <code>bitcoind</code> 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. </p>

<blockchain><json-rpc><script>
What are some good solutions for analyzing Bitcoin script patterns?
torkel
# What are some good solutions for analyzing Bitcoin script patterns?

(Asked by: username_0 on 2019-12-09)

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.

**Tags:** blockchain, json-rpc, script


---

## 3 answers

### Answer by username_1 on 2019-12-09. Score: 1 | Accepted answer

It seems that [bitcoin-iterate](https://github.com/rustyrussell/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.

> **Comments:**
> **username_0**: 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.  
> **username_1**: `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).  

---

### Answer by username_2 on 2019-12-13. Score: 1

I want to add my propose to this solution.

I have released the new parser called [SpyCBlock](https://username_2.github.io/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](https://username_2.github.io/AnalyticsPyBlock/).

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


---

### Answer by username_3 on 2019-12-10. Score: 0

You may try [blockchain-parser](https://github.com/ragestack/blockchain-parser).

It converts raw blockchain data to the simple text files.


---

