In my project for one particular functionality, I want to traverse through all the Transactions. For that purpose I want to traverse through all the blocks in blockchain.

1 Answer 1


If you are intent on doing it with c++, there is a blockchain parsing library that may help you here https://code.google.com/p/blockchain/.

Depending on your application, though, I might recommend just writing a terminal script to use the daemon. It probably won't be as fast, but I bet it would be easier to get up quickly. These commands can be called to get you the info you need:

// Gets the block at index index
./bitcoin-cli getblockhash {index}

// Gets the block using the result of the first statement
./bitcoind-cli getblock {hash} 

// The block has an array of transactions in it
for (Tx tx : block.tx) {
    ./bitcoind-cli getrawtransaction {tx} 1
  • What language is that? Or is it pseudocode?
    – Nick ODell
    Oct 28, 2014 at 17:22
  • Oh, and you have to use ./bitcoin-cli now.
    – Nick ODell
    Oct 28, 2014 at 17:23
  • Pseudo code. Yeah, you're right, I'll change.
    – morsecoder
    Oct 28, 2014 at 17:25
  • 1
    Also make sure you enable txindex=1 in your bitcoin.conf and run build the transaction index (bitcoind -reindex) before you iterate all (=also non-wallet) transactions.
    – behas
    Oct 29, 2014 at 8:34
  • Thank you very much for the answer. It is really helpful Stephen. By the way, Is there any method to retrieve the last index of the block received? If so it would be helpful for me to run a for loop to get all the blockhashes.
    – Rasela Don
    Oct 29, 2014 at 15:26

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.