First commands

We will set up a private blockchain with a single node. Start by opening two separate command-line prompts. In the first, run bitcoind (Bitcoin node server), while in the other, run one of the available RPC commands using bitcoin-cli <command>. To get the full list of RPC calls, you can use the help option bitcoin-cli --help, or visit the official documentation at https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list.

As a first command, we will generate quickly 101 blocks by running the following command:

bitcoin-cli generate 101

The expected output is a list of created blocks' IDs, similar to the following:

It is worth noting that in Regtest mode, you have to generate 100 blocks (100 confirmations) to get the initial reward (50 bitcoins) generated for the first block. We can check out how many bitcoins we have with the following:

bitcoin-cli --regtest getbalance
50.00000000

Instead of interacting directly using bitcoin-cli, you can run commands via the HTTP JSON-RPC tools. If CURL isn't installed, you can install it with sudo apt-get install curl. For example, you can request your balance by using CURL:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18443

Notice the presence of the RPC username and password defined earlier in bitcoin.conf, used with the option --user in the RPC call. 

You can also use REST calls to communicate with your bitcoin node. However, in this case, you'll need to enable the REST API by adding the option rest=1 to your bitcoin.conf file. The available calls are presented in the official documentation at https://github.com/bitcoin/bitcoin/blob/master/doc/REST-interface.md .

After successfully setting up the Regtest environment, what follows is a small introduction to transactions in bitcoin with some basic knowledge required to build the project.