top of page
Writer's pictureeconoalchemist

Build your own Bitcoin full node on a RaspberryPi.

These are the steps I took to build a fully validating Bitcoin node running BitcoinCore-qt.



Cautionary note:

If you value privacy and do not want the NSA to have access to your Bitcoin node, read this article and take this information into consideration. There is a potential backdoor to the Raspberry Pi's and if you want to build something on this hardware you should be aware of this potential risk. I have not confirmed this risk personally but it is worth considering. Thank you @LukeDashjr for sharing this article with me.


Introduction:

These instructions are meant for people interested in running a Bitcoin node. However, this only covers how to build a very specific configuration of a Bitcoin node: Built on a Raspberry Pi4 hardware, with a mini HDMI monitor, BitcoinCore v0.19.0.1 with the GUI, TOR enabled, wallet enabled, external SSD, and fully validating meaning that the node will accept incoming requests.

Before starting this project, I had no experience with Command Line Interfaces (CLI), Linux, or single-board computers. If you have a similar background and you want to run a Bitcoin node configured like this, then these instructions should be helpful to you. I made a lot of mistake and had to gather information from several different sources, so hopefully this saves you some time & effort. If you are a more advanced user, then these instructions may be too basic for you, or you may be looking for a more advanced configuration that is not covered here. However, there are links to informative resources that you may find useful. I may have some steps in here that you find unnecessary. For example, I prefer to load my library files one at a time, other people like to do several at a time. However, these are the steps I took to build my node. Again, I had no experience with this stuff before hand and I do not know exactly what a lot of these steps are doing. But this is how it worked for me.


Other helpful links:


Required Material:

  • Raspberry Pi4 This is the Cana Kit I purchased from Amazon:

  • Mini HDMI monitor This is the mini HDMI monitor I purchased from Amazon:

  • Keyboard, I used an old one I had laying around.

  • Mouse, I used an old one I had laying around.

  • 64GB Micro SD card, this came with the Cana Kit.

  • External SSD with a minimum 500GB capacity, I used an old one I had laying around. However, if you want to use a 512GB MicroSD card be forewarned that there are many scams on Amazon and other market places. I purchased one from Amazon and it took me several attempts and a lot of time to figure out that the MicroSD card was not in fact 512GB.

  • A separate, operating computer so you can format & preload your Micro SD card. I used an old Windows desktop.

  • A good internet connection and access to the router admin settings.

  • Ethernet cable, I used an old one I had laying around.

Hardware Assembly:

  • Assemble Raspberry Pi hardware, i.e., Canna Kit with case, heat sinks, ect.

  • Here is a link to help you with assembling the Raspberry Pi:

  • Do not power on the Raspberry Pi yet.

Format The MicroSD Card:

  • Your Raspberry Pi may have come with a preloaded 64GB MicroSD, in which case you can skip this section. But the point of this section is to get the NOOBS image loaded on your MicroSD Card.

  • Format a 64GB MicroSD card on a seperate computer.

  • This will be your boot disc for the Raspberry Pi.

  • Make sure it is formated to the FAT32 file system.

  • You might be prompted that the microSD card needs to be formatted before your computer can talk to it. It may be necessary to format it to exFAT with your native disc manager first if FAT32 is not an initial option.

  • Windows disc manager, for example, is accesible by opening your file explorer, right clicking on "This PC", and selecting "Manage".

  • There, you can right-click the appropriate drive and select 'format' and then follow the prompts.

  • The Raspberry Pi boot drive you are creating needs to be formatted to FAT32.

  • In my situation, Windows10 did not give me the option of formatting to FAT32, only exFAT.

  • My solution was to download GuiFormat.exe from

  • GuiFormat.exe will allow you to format the MicroSD card to FAT32 through the easy to follow prompts.

Load NOOBS:

  • Navigate to https://www.raspberrypi.org/downloads/noobs/

  • This is where you will download the NOOBS zip file.

  • I specifically chose to use NOOBS instead of NOOBS Lite because I wanted to have the desktop and the rest of the bells and whistles. The Noobs Lite seems to be better suited if you are building a headless node, which I did not.

  • As of this writing, NOOBS version 3.2.1 =

SHA256:9d040a0b2795e940cab848c612a9ccfd739cf7ea5fcb1d42141f93cefcef4078

  • You can use Windows to check SHA256.

  • Launch Windows Power Shell (not the CMD.exe)

  • From C:/ type "Get-FileHash" Followed by your file path, ending with filename.

  • For example: "PS C:\> Get-FileHash

C:\Users\your_user\Desktop\Raspberry_Pi\NOOBS_v3_2_1.zip"

  • Note, Windows Power Shell does not like spaces in your file-path, use an underscore where needed instead.

  • If your SHA256 result does not match, you should not proceed, you may have a compromised file.

  • Extract the contents of the zip file.

  • Copy all contents of the extraction to the newly formatted 64GB MicroSD card.

  • Safely eject the MicroSD card and while the Raspberry Pi is still shut off, and after the board has been installed in the case, install the MicroSD card in the MicroSD card port.

Format the External SSD:

  • Format an external hard drive on a separate computer.

  • Open your disk management program again and delete all volumes & partitions on your external drive so it is completely blank.

  • Now eject your SSD. Do not format it to any file system type. Do not create a new volume. This will be done on the Raspberry Pi later.

  • This will be the storage media for your Bitcoin blockchain; as of this writing, Bitcoin blockchain = ~240GB.

  • Do not connect your external drive to the Rasperry Pi yet.

Powering on the Raspberry Pi:

  • Connect your mouse, keyboard, Ethernet cable, & monitor to the Raspberry PI.

  • Turn the monitor on.

  • Connect the power supply to the Raspberry Pi.

  • The Raspberry Pi will turn on as soon as it is connected to power.

  • If you have a power switch in line, switch it on.

Initial Set Up:

  • The first time you turn on the Raspberry Pi it will initialize itself and partition your boot disc accordingly.

  • When prompted, select to install Raspbian Full.

  • Ensure your boot disc is selected as the destination.

  • Modify language if desired.

  • Click the "Install" icon in the upper left hand corner.

  • You will be warned that this operation will erase existing data on your boot disc, select "yes".

  • After ~20 minutes you should see a dialog stating "OS(s) installed ok".

  • Click "ok", then the Raspberry Pi will do a quick reboot.

  • You should see the desktop and the initial configuration window where you can select your location, time zone, & language.

  • Reset the "Pi" user password which is set to the default 'raspberry'.

  • Select your WiFi network, enter your WiFi password if you want. Your Ethernet cable should be providing your internet connection though.

  • If there is a black border around the edge of your screen, select the checkbox in the dialog window indicating so.

  • The Raspberry Pi will check for updates, install them, then prompt you to reboot, this should take ~15 minuets.

Command Line Interface:

  • The dollar sign ($) indicates the beginning of the command that you will be typing into your shell.

  • The hashtag sign (#) indicates a comment that I'm making and you do not need to type it out.

  • The semicolon sign (;) indicates the end of the command you are typing. You do not need to type the semicolon.

  • Now that the Raspberry Pi is configured and up to date, open the command shell.

  • The dafault user should be "pi@raspberrypi:~ $"

  • For the following steps outlined below, we can use some of the instructions found at https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md.

$sudo apt update;
$sudo apt upgrade;
$sudo apt install git -y;
$sudo apt install htop -y;
$sudo apt install curl -y;
$sudo apt install bash-completion -y;
$sudo apt install jq -y;
$sudo apt install qrencode -y;
$sudo apt install dphys-swapfile -y;
$sudo apt install hdparm -y;

Setting up TOR:

You don't have to use TOR, but it's a good idea if you're into privacy. I'm putting the TOR instructions here because I chose to set up TOR after configuring BitcoinCore and downloading the entire blockchain, unfortunately my node is not connecting through TOR so I suspect that if I had done these steps at the beginning instead of the end then it may have worked. If you want to reference the site where I found these instructions, navigate to https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html and see the section on Privacy. Or you can just skip the TOR section.

$ sudo nano /etc/apt/sources.list; 

This will open a file you need to edit.

$ deb https://deb.torproject.org/torproject.org buster main; 

Add this line after the existing line.

$ deb-src https://deb.torproject.org/torproject.org buster main; 

Add this line after that then press "ctl+x" to exit, "y" for yes, & "enter" for yes.

$ sudo apt install dirmngr apt-transport-https;
$curl 
https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import;
$ gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -;
$ sudo apt update;
$ sudo apt install tor;
$ tor --version;

This should return "Tor version 0.4.1.6." (or higher).

$ systemctl status tor;

Press "ctl+c" to exit.

$ cat /usr/share/tor/tor-service-defaults-torrc;

This should return a few lines with "User debian-tor" in them.

$ cat /etc/group | grep debian-tor;

This should return "debian-tor117:x:" or something similar.

$ sudo usermod -a -G debian-tor pi;

My user is "pi". Use whatever user you set up. Or if you left it default like I did, enter "pi".

$ cat /etc/group | grep debian-tor;

Now it should return "debian-tor117:x:pi"

$ sudo nano /etc/tor/torrc;

This will open another text file you need to edit by removing the hashtag signs (#) from the following lines (You need to scroll down to find them).

Uncomment:

ControlPort 9051
CookieAuthentication 1

Add:

CookieAuthFileGroupReadable 1
$ sudo systemctl restart tor;

Now restart your Raspberry Pi.


Connecting & Mounting External Drive:

Below are instructions for connecting your external SSD. Or you can follow the instructions for attaching an external drive found at:

in the Raspberry Pi section under Attach External Drive:

$sudo dmesg -C;
$sudo dmesg -w;

Now connect your external drive.

Make note of idVendor & idProduct. For example: idVendor = 1058 & idProduct = 0748

$ctl+c;
$lsblk -o NAME,MOUNTPOINT,UUID,FSTYPE,SIZE,LABEL,MODEL;

Make note of the partition name. For example: sda or sda1.

Test your external drive's performance with:

$sudo hdparm -t --direct /dev/XXX;

(Where XXX = your partition name).

You should get a result that reads something like: Timing O_DIRECT disk reads: 200 MB in 3.0 seconds = 66.66 MB/s.

If your results are less than 50 MB/s then follow the next step with your idvendor & idproduct from above. Otherwise, skip ahead to "$sudo mkfs.ext4...".

First edit the cmdline text file:

$sudo nano /boot/cmdline.txt;

At the very beginning of the text in the file insert:

usb-storage.quirks=XXXX:YYYY:u 

Where XXXX=idVendor & YYYY=idProduct. Make sure you leave a single space after the "u" and before the original text.

Save the text file by hitting ctrl+x, y for yes, and enter.

$sudo reboot;

Once you're all logged back in and back in the shell, re-run the performance test.

$sudo hdparm -t --direct /dev/sda1;

You should have increased performance. If not, get a new external drive and start again.

Format the partition on the external drive.

$sudo mkfs.ext4 /dev/XXXX;

Where XXXX = your partition name such as "sda".

In case your external drive was previously mounted, you can use "$ sudo umount /dev/sda" to unmount.

$lsblk -o NAME,MOUNTPOINT,UUID,FSTYPE,SIZE,LABEL,MODEL;

Make note of your external drive's UUID.

$sudo nano /etc/fstab;

Create a new line below the others that reads the following: where "{tab}" is you hitting the tab key.

UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX {tab} /mnt/ext {tab} ext4 {tab} defaults,noatime {tab} 0 {tab} 2

Where the UUID is what you copied from above. Hit ctrl+x, y for yes, & enter to save.

$sudo mkdir -p /mnt/ext;
$sudo mount -a;
$df -h /mnt/ext;

Should return:

Filesystem Size Used Avail Use% Mounted On
#/dev/sda 1.8T 77M 1.7T 1% /mnt/ext

Set the owner:

$sudo chown -R pi:pi /mnt/ext/;
$cd /mnt/ext;
$sudo mkdir -p bitcoin;
$ls -la;

If owner & group for the new bitcoin folder are root & root, then run:

$sudo chown -R pi:pi /mnt/ext/bitcoin;
$ls -la;

Bitcoin should now be owned by pi.

Let's test our permissions by creating a file & deleting it:

$touch bitcoin/test/file;
$rm bitcoin/test.file;

You should not receive any errors. If you do then your drive is mounted as read-only and you need to fix that before proceeding.

Move swap file:

$sudo nano /etc/dphys-swapfile;

Scroll down to "CONF_SWAPFILE=100" and put a (#) hashtag infront of it. Hit ctrl+x, y for yes, enter for save.

$sudo dphys-swapfile install;

Installing & Compiling BitcoinCore v0.19.0.1

$cd bitcoin;
$sudo git clone https://github.com/bitcoin/bitcoin.git;
$sudo apt install build-essential -y;
$sudo apt install libtool -y;
$sudo apt install autotools-dev -y;
$sudo apt install automake -y;
$sudo apt install pkg-config -y;
$sudo apt install libssl-dev -y;
$sudo apt install libevent-dev -y;
$sudo apt install bsdmainutils -y;
$sudo apt install python3 -y;
$sudo apt install libboost-all-dev -y;
$sudo apt install libprotobuf-dev -y;
$sudo apt install protobuf-compiler -y;
$sudo apt install libcanberra-gtk-module -y;
$sudo apt install libminiupnpc-dev -y;
$sudo apt install libzmq3-dev -y;
$sudo apt install libqt5gui5 -y;
$sudo apt install libqt5core5a -y;
$sudo apt install libqt5dbus5 -y;
$sudo apt install qttools5-dev -y;
$sudo apt install qttools5-dev-tools -y;
$sudo apt install libqrencode-dev -y;
$sudo apt install libboost-system-dev -y;
$sudo apt install libboost-filesystem-dev -y;
$sudo apt install libboost-chrono-dev -y;
$sudo apt install libboost-test-dev -y;
$sudo apt install libboost-thread-dev -y;
$sudo wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz;
$echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz' | sha256sum -c;
$tar -xvf db-4.8.30.NC.tar.gz;
$cd db-4.8.30.NC/build_unix;
$sudo mkdir -p build;
$BDB_PREFIX=$(pwd)/build;
$../dist/configure --disable-shared --enable-cxx --with-pic --prefix=$BDB_PREFIX;
$sudo make install;
$cd ../..;
$cd bitcoin;
$sudo git checkout tags/v0.19.0.1;
$sudo ./autogen.sh;

This should take a couple minutes to start running, don't freak out.

$sudo ./configure CPPFLAGS="-I${BDB_PREFIX}/include/ -O2" LDFLAGS="-L${BDB_PREFIX}/lib/" --with-gui --with-miniupnpc --enable-upnp-default --enable-hardening;

Note this line reads "-O2" which is the capital letter "O" not zero "0"

$sudo make;

This takes a long time to compile, don't freak out.

$sudo make install;
$sudo bitcoin-qt;

This should launch the BitcoinCore GUI.

When the Bitcoin Core GUI launches for the first time it asks you define the file path for storing the blockchain (~240GB at time of writing).

The default file path that Bitcoin Core chooses is /root/.bitcoin.

If you used a 64GB MicroSD card for your boot disc, then you'll probably only have ~48GB left in that directory.

Change the file path to: /mnt/ext/bitcoin/bitcoin and you should have all the remaining room on your external drive to consume.

The first thing your node will do is synchronize with the network. That means that it is going to download all the blocks in the Bitcoin blockchain starting with the genesis block from January 2009. This is roughly a 240GB download and it will take a lot of time and bandwidth. My initial down load took 10 days 9 hours.


Be Fully Validating:

Make sure your node is accepting inbound connections, this is what helps support the network:

  • Open a secondary shell and find your IP address by typing $ curl ifconfig.me;

  • This should return something like "83.160.81.177"

  • Navigate to: https://bitnodes.earn.com/#join-the-network

  • Enter that IP address and hit "CHECK NODE"

  • You should see a green text box validating that your node is connected and accepting inbound requests

  • You may need to log into your router and set up port forwarding to 8333

Extra Credit:

If you made it this far, congratulations on proactively participating in the Bitcoin network and empowering yourself to eliminate trust by verifying your own bitcoin transactions!

You can do some cool things with Remote Procedure Calls (RPC) like check transactions, network status, and various statistics. You should exercise caution and skepticism when working with any RPC, scammers have instructed unsuspecting users in ways that compromised their funds.

If you want to turn your node into your own blockchain explorer, you need to index your copy of the blockchain. I did this by opening the bitcoin.conf file by running $ sudo nano /mnt/ext/bitcoin.bitcoin.conf; and adding the line $ txindex=1; under # Miscellaneous options then I restarted BitcoinCore with the command $ bitcoin-qt -reindex; the initial indexing took about 5 hours and as of this writing, I'm on day 5 waiting for the blocks on disc to process.

Further instructions can be found in 'Mastering Bitcoin' 2nd addition by Andreas Antonopoulos starting in chapter 3, page 43. I highly recommend this book.

@peterjdurham put together a really cool article on building your own API using BitcoinCore's RPC functionality. I'm trying to implement this on my system currently. https://medium.com/@peterjd42/build-your-own-bitcoin-api-using-node-js-and-bitcoin-core-251e613623db


If you enjoyed this content, leave me a tip here: Donate.

2,739 views
bottom of page