Social media

How to extract transaction data from the bitcoin blockchain using bitcoin-cli?

Author: LB 2021-03-07 1182

Bitcoin has been built on a permissionless blockchain, and this means that basically anyone can join its peer-to-peer network. Well, as long as you have 350 Gb of free space and this number keeps growing. If you want to use bitcoin-cli, you have to download the entire bitcoin blockchain and synchronize the transaction data starting from the genesis block. I didn’t have a huge hard drive in my PC, so I decided to compile a bitcoin client on a virtual machine rented from Amazon AWS. I know the bitcoin community dissuades users from using cloud providers to run bitcoin clients, so this guide is strictly for educational purposes. Let’s see some of the difficulties I faced!

You can download the bitcoin core source from github by executing $ git clone Enter the downloaded directory with $ cd bitcoin.

You need a few essential software to compile the bitcoin source and you can install these on Ubuntu with the following command: $ sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 autoconf libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev libboost-iostreams-dev libevent-dev

Now you can run $ ./

And then $ ./configure.

If you want to generate a bitcoin wallet for yourself, be sure to run configure with wallet support, otherwise wallet functionality will be completely disabled in bitcoin-cli.

If ./configure was successful, you can compile the source code with $ make -j7 on 7 threads. Adjust this number according to the number of cores you have in your machine if you want fast compilation.

The compilation of bitcoin core takes a while, even on a few cores. As soon as it finishes, you can run the bitcoin daemon with $ ./bitcoind -daemon in the background.

This will start the synchronization process and it took a bit less than a day for me to download roughly 350 Gb of blockchain data.

You can check the progress of the blockchain synchronization in your home directory, under .bitcoin. The “debug.log” file will tell you the current blockheader the daemon is synchronizing. You can find the downloaded blockchain under the “blocks” directory.

This is how the synchronization log looks like:

As soon as you synchronized the blockchain, you can use $ ./bitcoin-cli createwallet "[YOUR WALLET NAME]" to create a new bitcoin wallet on your computer and you can use $ ./bitcoin-cli getwalletinfo to query your account balance. Unfortunately, you’re not able to query other wallets’ balance with this client. This is due to the fact that the bitcoin blockchain has been invented to store transaction data and not wallet balances. In order to retrieve the balance of a given address in a wallet, one would have to iterate through the entire chain and check for transaction that modify the balance of the given account. By summing all the incoming transactions and subtracting the outgoing transactions one can calculate the balance of the accounts, but this is a pretty lengthy process.

My goal was to access transaction data stored on the blockchain. By default, the bitcoin daemon downloads the entire blockchain, however it doesn’t build a transaction index, and you cannot search for a specific transaction using its transaction identifier. If you want to enable this functionality, you have to create a “bitcoin.conf” file to configure your client and set txindex=1. After this, make sure to reindex your local blockchain with $ ./bitcoind -rescan.

Now you can use $ ./bitcoin-cli getrawtransaction “[Transaction identifier hash]” true to extract transaction data in JSON format from your local synchronized blockchain.


Interesting entries


Best GPUs to mine ethereum in 2022


Dual mining ethereum and toncoin on RTX 3060Ti and RTX 3070Ti LHR


Profiling the RTX 3060 Ti and its memory transfer rate


Core clock settings for RTX 3060 Ti when mining Ethereum


Core clock settings for RTX 3070 Ti Founders Edition when mining ethereum