Now that we’ve covered the history behind Bitcoin and have a theoretical understanding of how blockchains function, let’s see it in action.

Thus far when we have said “node” we meant “full node”. As mentioned, full nodes keeps a complete copy of the Bitcoin blockchain and participates in network consensus by checking and forwarding valid transactions. They download every block and transaction and check them against Bitcoin’s consensus rules.
 

THINGS A “FULL NODE” DOES


  • Keep a complete copy of the blockchain
  • Maintain connections to peers
  • Validate incoming data (transactions and blocks)
  • Distribute valid data

In these ways, a full node contributes to network “consensus”.

SPV nodes reminder: Lightweight or thin clients are nodes that use Simplified Payment Verification. SPV is a method for verifying that particular transactions were included in a block without downloading the entire blockchain. This allows you to run software that interacts with the bitcoin network on low resource machines, such as running a wallet on a smartphone. However, using SPV instead of full nodes means the loss of some privacy and security.

Before we can set up a node there are two more things to consider. Do we want to run on mainnet, testnet or regtest? And which Bitcoin implementation do we want to use?

Mainnet

Mainnet is the live Bitcoin network. To fully participate in the Bitcoin ecosystem you’ll want to be running a mainnet node. However, when starting out and testing new applications mainnet is likely not the best option as it comes with the risk of losing coins which have real value. To run a mainnet full node you will need to download the entire ~200GB blockchain.

Testnet

Testnet is a public bitcoin network that is used by developers around the world to test Bitcoin applications. You can find and use Bitcoin testnet coins and exchange them with others on the testnet. These coins very intentionally have no exchange value; they are used simply for testing. To run a testnet node you will need to download the testnet blockchain which is significantly smaller than mainnet at only ~20GB.

Regtest

Regtest allows you to set up your own local blockchain. When you start a node in regtest mode there is no blockchain data to download. You need to create all the blockchain data yourself!

Once you know what network you want to run on, you’ll need to choose a client or implementation. Bitcoin core (formerly Bitcoin-Qt), is the reference implementation and is still the most commonly used bitcoin implementation. It is written in C++. However, there are now a number of other options such as Bitcore witch is written in Node.js or btcd which is written in GoLang.

Here we will walk through instructions for both Bitcoin’s testnet and running in regtest mode using the reference implementation Bitcoin Core, or more specifically the bitcoind daemon.

NOTE:The below instructions are for Ubuntu machines. Mac OS and Windows instructions can be found here.

 

UBUNTU INSTRUCTIONS


$ apt-add-repository ppa:bitcoin/bitcoin
$ apt-get update
$ apt-get install bitcoind

 

BITCOIND RESOURCES


Once you have the software installed, we’ll need to configure it.
 

TESTNET INSTRUCTIONS


Start bitcoind
$ bitcoind -testnet -printtoconsole -daemon -server
View the debug log in a separate console window
$ tail -f .bitcoin/testnet/debug.log
Create a config file in .bitcoin
$ touch bitcoin.conf
 

THE BITCOIN.CONF FILE


# Set up RPC

server=1

rpcuser=test

rpcpassword=test

rpchost=127.0.0.1

rpcport=6163

# Run on the testnet

testnet=1

# Specify a directory for testnet data

#datadir=/home/bitcoin/.bitcoin/testnet

 

REGTEST MODE INSTRUCTIONS


NOTE:Learn more about regtest.

Start bitcoind in regtest mode
$ bitcoind -regtest -printtoconsole -daemon -server
View the debug log in a separate console window
$ tail -f .bitcoin/regtest/debug.log
Create a config file in .bitcoin/regtest
$ touch bitcoin.conf
 

THE BITCOIN.CONF FILE


# Set up RPC

server=1

rpcuser=test

rpcpassword=test

rpchost=127.0.0.1

rpcport=6163

# Run on a regtest network

regtest=1

# Connect only to the specified node

connect=[your local IP]

 

TRY OUT SOME COMMANDS


Kill bitcoind and restart
$ pkill -9 -f bitcoind
$ bitcoind [-regtest or -testnet] -printtoconsole -daemon -server

Use bitcoin-cli to view your connection to peers
$ bitcoin-cli [-regtest or -testnet] -getinfo
Generate a new address to receive coins
$ bitcoin-cli [-regtest or -testnet] getnewaddress
Check your balance
$ bitcoin-cli [-regtest or -testnet] getbalance
Now that we’ve had a chance to experience bitcoin on the command line, let’s take a step back in our next lesson and be sure we understand in more depth what a bitcoin is.