Build a Bitcoin Full Node on Raspberry Pi

How to Build a Bitcoin Full Node on a Raspberry Pi

Hello there!

Today, I’m going to show you how to build a Bitcoin full node on the Raspberry Pi. This is a great project for anyone who wants to support the Bitcoin network while validating their own transactions. As the Bitcoin network grows, it’s important that people maintain their full nodes. We need to constantly bring new nodes onto the network to keep it decentralized and healthy.

Glossary:

1. Setup the Rasfpberry Pi 3
2. Install the External Hard Drive
3. Increase the Swap File
4. Install the Bitcoin Core Dependencies
5. Install Bitcoin Core
6. Starting the Bitcoin Core Client
7. Download the Blockchain on another Machine (Optional)

 

What is a Bitcoin Full Node?

A Bitcoin full node is much simpler than it sounds. A full node is simply a computer that is running the Bitcoin Core Wallet. The Bitcoin Core Wallet, by default, downloads a full copy of the Blockchain.

Why do you need a full copy of the Blockchain?

Similar to BitTorrent and other peer to peer networks, you have to download the Blockchain from other people. If you’ve ever downloaded a torrent, you’ll notice that some of them have seeders while other don’t. These “seeders” are people who have already downloaded the file, and have opted to let you download part of the file from them. Without seeders, the BitTorrent network wouldn’t exist.

The Bitcoin network operates the same way. When people try to access their Bitcoin, they are using a wallet that has access to at least part of the network. If people didn’t have full nodes, we wouldn’t be able to verify transactions or see transactions from the past. You wouldn’t be able to access your Bitcoin because ultimately, without nodes, your Bitcoin wouldn’t exist.

How do you Build a Bitcoin Full Node?

We are going to use a Raspberry Pi 3. The Raspberry Pi is a small, inexpensive computer, that has just enough specifications to allow us to operate a full node. We are going to download the Blockchain on an external hard drive on a separate machine using the Bitcoin Core Wallet.

After we have downloaded a full copy of the blockchain, we are going to connect the external hard drive to the Raspberry Pi so that it can continue to build it.

It is possible to directly download the blockchain onto the Raspberry Pi, but it will take a lot of time.

Things we are going to Need:

 

Raspberry Pi 3

The Raspberry Pi is a phenemonal computer. What makes it so great is that it’s about the size of a credit card and it costs less than $40. The Raspberry Pi can run both Linux and Windows.

For our Bitcoin full node, we are going to use Linux. This is due to the fact that Linux is more lightweight and we are going to need all of the resources that the Raspberry Pi can offer.

Usually Raspberry Pi’s will come barebones. The kit that we purchased comes the Touchscreen, Case, SD Card (which will hold the operating system), and Heatsinks.

LCD Touchscreen

The LCD Touchscreen is an optional component for this project. The Raspberry Pi has a HDMI port built in which can be used to project on any monitor/tv that is HDMI capable. For my full node, I wanted to have a touch screen that displays the current price of Bitcoin.

Plus I plan on sending and receiving Bitcoin directly from my node, and having a designated screen would make this process much easier. Plus it looks cool.

Our kit will use a LCD Touchscreen that is compatible with the Raspberry Pi. It also fits perfectly in the case.

Raspberry Pi Case

The Raspberry Pi case once again is optional. I wanted something that would contain both my Raspberry Pi and LCD Touchscreen. The kit that I purchased provided one that was simple and lightweight. This is perfect since I want my Raspberry Pi to be simple yet stylish.

Raspberry Pi Wireless Keyboard

This little device is optional, but it makes operating the Raspberry Pi way easier. Without it, you will have to plug in a desktop USB and Mouse or SSH into the Pi.

I definitely recommend picking it up since its only $20 and it will make your life a lot easier.

1 TB Hard Drive


The 1TB Hard Drive is necessary for storing the Blockchain. At the time of writing this (08/13/17)  the Bitcoin blockchain is approximately 130GB. You can check the current size by clicking on this link.

Currently, the blockchain is growing at about 50GB a year. As Bitcoin gains popularity in the coming years, it is destined to grow at a much faster rate. For the sake of longevity, I strongly recommend that you purchase a hard drive that will last for years to come.

If a 1TB Hard Drive is too far out of your price range, you can always start smaller and upgrade once you outgrow it.

How to Build a Bitcoin Full Node on a Raspberry Pi


1. Setting up the Raspberry Pi

Setting up the Raspberry Pi is simple. If you purchased a Raspberry Pi kit that already has Raspbian installed, you simply need to put in the SD card and plug it in.

For those of you that need to install linux on a blank SD card, you can follow this guide on the RaspberryPi.org website.

Update the the Raspbian Software

sudo apt-get update

Update Raspbian Repositories

sudo apt-get upgrade

Update Raspberry Pi


2. Install the External Hard Drive

Now that we have Raspbian up and running, we are going to partition the hard and mount it.

First, let’s connect the external hard drive to the usb port on the Raspberry Pi.

After we have connected the external hard drive to the Raspberry Pi we are going to run a command to see if it was identified.

sudo fdisk -l

List External Hard Drive

As you can see, the hard drive is showing up at the bottom, and it’s labeled “/dev/sda”. We are now going to access the drive, format it, and partition it. Just as a warning, anything on the drive is going to be erased after this process. If you have anything important on it, I advise you to transfer off that information before doing this.

Type in the following command.

sudo fdisk /dev/sda

 

Now that we are in the drive, you should see this screen.

Enter “d” so that we can delete the partitions that are currently on the hard drive. Keep entering “d” until you receive a message telling you that there are no more partitions on the hard drive.

d

 

Now, it’s time to create our new partition. To do this, type in “n”.

n

 

You will be given the options to create a primary partition or an extended partition. Type in “p” to choose primary partition.

p

 

You will now be prompted to number the partition. Choose “1” so that your drive will be named “/dev/sda1”.

/dev/sda1

 

For the next two questions about the first and last sector, simply hit enter for both of them so that it chooses the default.

Now that you have created your new partition, it’s time to exit out of “fdisk” Type in “w” to exit fdisk.

w

 

Now it’s time tor format your new partition. We are going to partition it as “Fat 32”. By partitioning the system as Fat32, we ensure that the hard drive will be compatible with both Windows and Mac. This will come in handy if you decide to download the blockchain using one of those two operating systems.

sudo mkdosfs -F 32 -I /dev/sda1

After the command has finished, you will have a newly partitioned hard drive! Now it’s time to set the drive to automatically mount.

Before we edit the configuration file, let’s create the Bitcoin data directory.

mkdir .blockchain

Now it’s time to make modifications to the configuration file. Use the command below to access the configuration file.

sudo nano /etc/fstab

Once we are in this configuration file, we will add this line so that the hard drive is automatically mounted to our “.blockchain” folder. Remember to replace “pi” with whatever your Raspberry Pi’s username is.

/dev/sda1 /home/pi/.blockchain ext4 defaults 0 0

Hit Ctrl-x and then hit Y so that we can save the file. Now, restart the Raspberry Pi so that we can confirm that the Raspberry Pi is automatically mounting the external hard drive.

Run the command below so that we can see if the drive has be mounted under our folder “.blockchain”.

df -h

If you see your drive “/dev/sda1” mounted on “/home/pi/.blockchain” then you are ready to proceed!


3. Increase the Swap File

A swap file allows the Micro Sd Card in the Raspberry Pi to be used as ram. This step is important if you are going to download the whole blockchain using the Raspberry Pi. If you plan on downloading it on a separate device, this step isn’t necessary.

Let’s start by editing the file “/etc/dphys-swapfile”.

sudo nano /etc/dphys-swapfile

We are going to change the default size of the swap file from 100 to 1000.

Find the line:

CONF_SWAPSIZE=100

To:

CONF_SWAPSIZE=1000

Hit CTRL-X and then Y to save the file.

Run the commands below to initiate this new swap file.

sudo dphys-swapfile setup
sudo dphys-swapfile swapon


4. Install the Bitcoin Core Dependencies

Before we install the actual Bitcoin Core software, we need to download certain dependencies that the software relies on.


sudo apt-get install protobuf-compiler libminiupnpc-dev libevent-dev libtool libssl-dev libboost-all-dev qt4-dev-tools libprotobuf-dev libqrencode-dev autoconf

After those dependencies are installed, we are going to need to install git. Git is going to be used to access download the Bitcoin Core source code from the GitHub repository. In case you don’t know what that is, it’s a commonly accepted platform that distributes source code for all types of applications.

sudo apt-get install git -y

Bitcoin Core uses Berkeley Database for their wallet system. It specifically relies on version 4.8. Berkeley is created by Oracle, which is the same company that creates Java.

We are going to make a directory that we can download and install the database into.

mkdir ~/bin
cd ~/bin

Now that we are in the new directory that we have created, let’s download the tar for the Berkeley Database.

wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz

Download Berkeley Database

Now that you’ve downloaded the Berkeley database, you’ll use the following command to extract it.

tar -xzvf db-4.8.30.NC.tar.gz

Now that we have extracted the Berkeley Database, let’s go into the directory prepare the source code for installation. This process can take anywhere from 5 to 20 minutes.


cd db-4.8.30.NC/build_unix/
../dist/configure --enable-cxx
make

Once the command has finished, it’s time to install the Berkeley Database.


sudo make install

Excellent! Now that the Berkeley Database is installed, we are now ready to install the Bitcoin Core Client!


5. Insall the Bitcoin Software

The first thing we are going to do is go back into the bin directory. Once we are in the bin directory, we are going to down the Bitcoin Core source code into it.

The “git” command is going to pull the source code from the GitHub repository. Use “-b” to specify to the version/branch of the source code that you want to download.

You can visit: https://bitcoincore.org to find out which version of Bitcoin Core is most recent.

Note: This command will download the latest version of Bitcoin Core V.14. You will want to replace the 0.14 with the latest version that is currently out.


cd ~/bin

git clone -b 0.14 https://github.com/bitcoin/bitcoin.git

cd bitcoin/

 

Now that we have download the Bitcoin Core source code, it’s time to prepare it for installation. After you run the “make” command, be prepared to wait a few hours before you are ready to complete the installation.


./autogen.sh

./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --enable-upnp-default --with-gui

make

 

Bitcoin Core is now ready to be installed. Run the code below to finish the install.

sudo make install

Congratulations! Your Bitcoin Core client is now installed!

6. Starting the Bitcoin Core Client

Before you start your Bitcoin client, you have to open port 8333 on your router and point it to your Raspberry Pi. This is required so that your new full node can allow incoming connections.

To Start the Bitcoin Core Client, simply type in the command below. This will start the Bitcoin core client using our mounted hard drive “.blockchain”.

If you followed the section that explained how to mount your external hard drive then it should start downloading directly onto your hard drive.

This process can take a long time since the Raspberry Pi’s resources aren’t that of a full blown desktop. If you want to speed up this process, go to step 7 and download the Blockchain on another computer.

bitcoin-qt -datadir=/home/pi/.blockchain

After you have completely synced your Bitcoin Core Client with the Blockchain,  hover your mouse over the little icons at the bottom right of the client. A little display will pop up showing how many connections your client has. If you are showing more connections than 8, you have successfully configured your full node!


7. Download the Blockchain on a separate Computer (Optional)

To speed of the download of the blockchain, I recommend downloading it on your main machine. You can download Bitcoin Core on Windows, Mac, and Linux.  After you download Bitcoin Core, start it up and let the blockchain sync. This can take several days to complete, so make sure that whichever computer you use can withstand being run non-stop during that time.

Downloading the Blockchain on Ubuntu

It is just as simple to download the blockchain on Ubuntu as it is on the Raspbian OS. Once you have downloaded and installed Ubuntu on your main computer, open terminal.

Installing Bitcoin Core on Ubuntu

This first command will tell Linux where to download the Bitcoin Software. The second will update Linux’s information on which packages are available.

sudo add-apt-repository ppa:bitcoin/bitcoin
sudo apt update

This command will install both the Bitcoin Core command line and the Bitcoin Core GUI interface.

sudo apt install bitcoind bitcoin-qt

This command will update your Linux Distribution.

sudo apt upgrade

Mounting the External Hard Drive to your Ubuntu System

Create a new .blockchain directory

sudo mkdir ~/.blockchain

Find out the name of the external hard drive’s partition

sudo fdisk -l

Below you can spot out your hard drive usually in this area.

Mount the external hard drive

sudo mount /dev/sda1 ~/.blockchain

These two commands will give your user the permissions to access the external hard drive. This is necessary for the Bitcoin Core software to access the drive.

sudo chown pinode /home/ubuntu/.blockchain
sudo chgrp pinode /home/ubuntu/.blockchain

Now that we have installed Bitcoin Core and mounted the hard drive, it is time to start the Bitcoin Core Client!

bitcoin-qt -datadir=/home/pi/.blockchain

The GUI for Bitcoin Core should open following this command. It will show you a screen that has details regarding how many more blocks need to be downloaded, how long it will take, what time period of the blockchain you are downloading (This part is cool, it’s kind of like going back in time).

After the blockchain has completely downloaded, let’s unmount it and then mount it on the Raspberry Pi.

sudo umount /dev/sda1

Unplug the external hard drive from your main machine and then plug it into the Raspberry Pi.

Restart or turn on your Raspberry Pi, and run the Bitcoin Core Client.  After the Bitcoin Core Client starts up, check if the blockchain is fully downloaded by hovering your cursor over the checkmark at the bottom right of the client.

In Conclusion

Building a Bitcoin full node on a Raspberry Pi is much simpler than it seems. After you purchase all of the parts, it’s simply a matter of running the necessary commands and opening the port 8333 on your router.

A full node isn’t necessary to send and receive Bitcoin, but it’s necessary to keep the network healthy. By allowing incoming transactions to your node you are verifying transactions and allowing the blockchain to be downloaded. What makes Bitcoin so special is it’s ability to be maintained by the people who use it.

Let’s continue to keep Bitcoin alive and well by doing all that we can to let out voice be heard throughout the Bitcoin network.

If you have any questions or contributions to this guide, I’d love for you to either comment below or email me at Nick@BuildaMiningRig.com!