I’ve wanted to run a Bitcoin full node for a while now. Not because it makes any money, quite to the contrary, it actually costs money to run a node, but to better understand a technology there’s nothing better than learning by doing 🧠
A full node is a program that fully validates transactions and blocks. Almost all full nodes also help the network by accepting transactions and blocks from other full nodes, validating those transactions and blocks, and then relaying them to further full nodes.bitcoin.org – What is a full node?
Once you have a full node running you can also query the blockchain locally using the command line or from Python for example, plus if you allow inbound connections you are contributing to the network.
I wanted the setup to be cheap, easy and reliable so using a Raspberry Pi was the obvious choice. My first attempt was a few months ago using a Raspberry Pi 3 Model B+ I bought second hand for next to nothing. I managed to get it up and running but the strain of the initial blockchain download and synchronization (currently running at 275 GB) would frequently crash the Pi due to lack of memory. Slightly frustrated I gave up and parked the idea for a while.
A New Start
Skip forward a few months and now the Raspberry Pi 4 is available with way better performance 🚀
I bought the 4 GB version that’s now running the headless (no GUI) version of Raspbian Buster Lite and is connected to an external 1 TB hard drive. I use SSH to connect so no need for mouse, keyboard or screen, just power and a network connection.
First a WARNING. Don’t do this if you have a metered or capped internet connection as you’ll be downloading the entire Bitcoin blockchain of 275 GB (currently).
I won’t cover the details for initial setup of your Raspberry Pi as there’s a full guide from the Raspberry Organization.
Likewise the Bitcoin Core install details have been extensively documented by many others, the guide I used was RaspiBolt on GitHub. I didn’t get as far as installing Lightning but the guide is excellent and unlike many guides I’ve tried works 100% if you follow every step carefully. The only deviation I made was starting my node directly on Bitcoin Mainnet (instead of testnet) by editing this one line in the bitcoin.conf so testnet=1 is commented out.
# remove the following line to enable Bitcoin mainnet #testnet=1
The entire install including initial setup of the SD card took about 1-2 hours but you learn a lot along the way, the basic steps being:
- Download and install Pi OS to SD card
- Enable ssh
- Setup your local network
- Create users on the Pi
- Mount external disk
- Setup firewall and security
- Download and install Bitcoin Core software
- Configure and start Bitcoin Core
- Grab a ☕ or ☕ ☕ and wait
Progress So Far
You can see below that I started the software about 4 days ago.
Using the bitcoin-cli command you can query the bitcoin process. You can see in the last 4 days I’ve downloaded 160030715927 bytes or about 160 GB and that my 1 TB disk is 20% filled with 173 GB of data stored.
To see all the possible commands type ‘bitcoin-cli help’ (there’s a lot!)
$ bitcoin-cli help == Blockchain == getbestblockhash getblock "blockhash" ( verbosity ) getblockchaininfo getblockcount getblockhash height getblockheader "blockhash" ( verbose ) getblockstats hash_or_height ( stats ) getchaintips getchaintxstats ( nblocks "blockhash" ) getdifficulty getmempoolancestors "txid" ( verbose ) getmempooldescendants "txid" ( verbose ) getmempoolentry "txid" getmempoolinfo getrawmempool ( verbose ) ...
To make it easier to see exactly how far I am from synchronizing the full blockchain I added this script to my Pi. Just paste this code into your text editor (nano or vi for example), save the file (as blocks.sh in my case) and make it executable with chmod +x blocks.sh
#!/bin/bash BC_CURRENT=`bitcoin-cli getblockcount 2>&1` BC_HEIGHT=`wget -O - http://blockchain.info/q/getblockcount 2>/dev/null` perl -E "say sprintf('Block %s of %s (%.2f%%)', $BC_CURRENT, $BC_HEIGHT, ($BC_CURRENT/$BC_HEIGHT)*100)"
Now to see my progress I can run the script using ./blocks.sh
Almost 86% done so I’ve got a few more days to go ☕☕☕