Bitcoin Core

Blockchain Fundamentals Course Materials


Bitcoin Core

The application that runs Bitcoin is called Bitcoin Core. This is the main implementation of Bitcoin which is a continuation of the original software by Satoshi Nakamoto. Others have made implementations as well, but this is by far the most widely used. We’ll get familiar with the software in this lesson.

First of all, the software is an open source collaborative project which currently has a list of over [600 contributors]. Anyone can contribute, and any contributions are peer reviewed by the code maintainers. Ultimately users of Bitcoin can run any software they want, but are incentivized to follow the same consensus rules so their coins remain valuable. We are going to start by installing Bitcoin Core locally, but instead of connecting to the main network and syncing the blockchain from scratch (which can take hours or days depending on your machine), we’ll run it in regression test mode. This will allow us to generate blocks quickly without having to compete with other miners since it is just an isolated system running only on our machine.

Installation

  1. Download Bitcoin Core v0.17.0.1 from bitcoincore.org/
    $ wget https://bitcoincore.org/bin/bitcoin-core-0.17.0.1/bitcoin-0.17.0.1-x86_64-linux-gnu.tar.gz
    
  2. Unzip the file
    $ tar xvzf bitcoin-0.17.0.1-x86_64-linux-gnu.tar.gz && cd bitcoin-0.17.0
    
  3. Install binaries
    $ sudo cp bin/{bitcoind,bitcoin-cli,bitcoin-tx} /usr/local/bin
    $ mkdir -p /usr/share/man/man1
    $ sudo cp share/man/man1/* /usr/share/man/man1
    

Running Bitcoin Core

Now, you can start the software in regression test mode (don’t forget the -regtest flag!):

$ bitcoind -regtest -daemon

-daemon will run the application in the background

Command Line Interface

Bitcoin Core has a command line interface used to issue commands and control the bitcoind process. You can learn about the cli tool by looking at it’s manpage:

$ man bitcoin-cli

Note that since it is just a client for bitcoind JSON-RPC, which allows you to send commands from a different process. To get a list of commands you can use:

$ bitcoin-cli -regtest help

If you want more details about a specific command you can execute, for example:

$ bitcoin-cli -regtest help getblockcount

There is also online documentation of the RPC methods at https://bitcoincore.org/en/doc/

To stop the application, you can use:

$ bitcoin-cli -regtest stop

File structure

Bitcoin Core, by default, stores related files on Linux in /home/{username}/.bitcoin. For the regtest network files are stored in /home/{username}/.bitcoin/regtest.

Let’s look at the folder structure:

$ find ~/.bitcoin
/home/jbaczuk/.bitcoin
/home/jbaczuk/.bitcoin/wallets
/home/jbaczuk/.bitcoin/regtest
/home/jbaczuk/.bitcoin/regtest/.cookie
/home/jbaczuk/.bitcoin/regtest/debug.log
/home/jbaczuk/.bitcoin/regtest/peers.dat
/home/jbaczuk/.bitcoin/regtest/wallets
/home/jbaczuk/.bitcoin/regtest/wallets/wallet.dat
/home/jbaczuk/.bitcoin/regtest/wallets/database
/home/jbaczuk/.bitcoin/regtest/wallets/database/log.0000000001
/home/jbaczuk/.bitcoin/regtest/wallets/db.log
/home/jbaczuk/.bitcoin/regtest/wallets/.walletlock
/home/jbaczuk/.bitcoin/regtest/fee_estimates.dat
/home/jbaczuk/.bitcoin/regtest/mempool.dat
/home/jbaczuk/.bitcoin/regtest/bitcoind.pid
/home/jbaczuk/.bitcoin/regtest/blocks
/home/jbaczuk/.bitcoin/regtest/blocks/blk00000.dat
/home/jbaczuk/.bitcoin/regtest/blocks/index
/home/jbaczuk/.bitcoin/regtest/blocks/index/000016.ldb
/home/jbaczuk/.bitcoin/regtest/blocks/index/000015.log
/home/jbaczuk/.bitcoin/regtest/blocks/index/LOCK
/home/jbaczuk/.bitcoin/regtest/blocks/index/MANIFEST-000013
/home/jbaczuk/.bitcoin/regtest/blocks/index/CURRENT
/home/jbaczuk/.bitcoin/regtest/blocks/rev00000.dat
/home/jbaczuk/.bitcoin/regtest/banlist.dat
/home/jbaczuk/.bitcoin/regtest/chainstate
/home/jbaczuk/.bitcoin/regtest/chainstate/000016.ldb
/home/jbaczuk/.bitcoin/regtest/chainstate/000015.log
/home/jbaczuk/.bitcoin/regtest/chainstate/LOCK
/home/jbaczuk/.bitcoin/regtest/chainstate/MANIFEST-000013
/home/jbaczuk/.bitcoin/regtest/chainstate/CURRENT
/home/jbaczuk/.bitcoin/regtest/.lock
/home/jbaczuk/.bitcoin/blocks

There are a few folders to point out. First, you’ll notice the blocks folder. Blocks are stored in .dat files, which are indexed by the .ldb files. These are levelDB files which contain indexes of the blocks, which file they are in, and where they can be found. The chainstate folder contains levelDB files for the current state of the blockchain’s unspent transactions. This contains only transaction outputs that are unspent to help speed up validation (so the application doesn’t have to search through the entire blockchain to see if a coin has been spent). Finally, Bitcoin Core also has a wallet (wallets folder) which lets users send and receive Bitcoin. There are other log files and settings that we’ll go over later.