How can I use the jsonRPC for the bitcoin client to export the chain into mysql and then sync the two as transactions come in? I'm writing a blockchain explorer for a new alt coin and unfortunately ABE won't work for this particular coin. I can query the chain using jsonRPC just fine for each transaction but I want to be able to store the chain in mySQL for speed and efficiency later on.

Preferred technologies: php & mysql.

2 Answers 2


You can't use jsonRPC to do this, because jsonRPC commands like gettransaction only work for wallet addresses you have in your wallet. They don't work for arbitrary addresses.

Sites like blockchain.info basically read the physical blockchain files, not using jsonRPC. You could do something similar. I've heard that bitcoinj may do what you want, but I've never used that library. You also want to check into Bitcore from BitPay.

  • The Bitcore project looks fantastic and is exactly what I think we can use. Thanks much - I can't upvote I do not have enough but I accepted the answer.
    – 6paq
    Mar 18, 2014 at 21:50

This is not trivial, have you thought about chain reorgs?

This is a client side phenomenon, depending on who you're connected to in the P2P network. If there's a race between two miners - they publish two blocks, A and B, at the same time, some people will believe one or the other. Eventually one of the chains will be elongated making it the longest and valid chain. We'll say that B was added to. Any tx's in A would no longer be valid, so your app needs to deal with this, and not show duplicate transactions.

I'm not entirely sure on the behavior from the client either - if a reorg is 3 blocks deep, does it issue callbacks (blocknotify) on all 3 new blocks? Or just the highest, best block? Maybe you need to recurse backwards from the latest block every time until you find a parent block you've already encountered?

Scaling is an issue here - I've started down this path before and you need to try reduce the number of queries you make over the RPC. Try decoding transactions using https://github.com/Bit-Wasp/bitcoin-lib-php instead of using the RPC, maybe that'll help.

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.