Using Raspberry Pi To Run A Full Bitcoin Node

Secured By Tor

Ishaana Misra
9 min readJul 16, 2021

In June, I started learning more about Bitcoin, decentralized peer-to-peer electronic cash. You can read more about Bitcoin in this article.

Running a full Bitcoin node is a good way to learn more about Bitcoin and see the Blockchain in action. Running a node also helps strengthen the Bitcoin network.

Components & Their Uses

  • Raspberry Pi 4(4GB RAM)
  • Case: keeps the Raspberry Pi(Raspi) safe.
  • Heat Sinks: helps prevent the Raspi from overheating.
  • Cooling Fan: helps prevent the Raspi from overheating.
  • MicroSD Card(64GB): stores Raspi data(not blockchain data)
  • USB MicroSD Card Reader: allows us to download an operating system for the Raspi from a computer.
  • Solid State Drive(1TB): this is where we will store the blockchain.
  • Solid State Drive Enclosure: allows the SSD to be an external hard drive(since the SSD I had could be used as an internal or external hard drive).
  • Keyboard + Mouse/Trackpad: allows for interaction with the Raspi.
  • TV or Monitor: allows for interaction with the Raspi.
  • Laptop: downloading Raspberry Pi OS to the MicroSD and configuring the SSD.
  • USB-C Power Supply: powers Raspi.
  • Micro HDMI Cable: allows for connection between the TV and the Raspi.

Setting Up The Raspberry Pi

Since I hadn’t used one before, the first thing I needed to do was set up my Raspi. After Putting the Raspi into the base of the case, I attached the heat sinks to their corresponding locations. Next, I attached the fan to the top of the case and connected the red and black wires to GPIO pins 4 and 6, respectively. At this point, it looked like this:

Once I snapped the top of the case on, I needed to install Raspberry Pi OS on my MicroSD card using Raspberry Pi Imager. I inserted my MicroSD card into the USB MicroSD Card Reader and plugged it into my laptop. The first thing I would have done would be back up my MicroSD card, but since it was new I didn’t need to do that. Instead, I navigated to the Raspberry Pi OS download page. From there, I downloaded it for macOS. Then I opened up the application, chose the OS(Raspberry Pi OS(32-bit)), and chose the storage(MicroSD Card). With that done, I ejected the MicroSD card from my computer, took it out of the MicroSD Card Reader, and put it into the correct slot in the Raspi.

Next, I needed to place the SSD in the enclosure. I wouldn’t have needed to do this if I had an SSD made just for being an external hard drive, but I needed to use an enclosure since my hard drive could be used both internally and externally.

Once inside the enclosure, I plugged the SSD into one of the USB ports on the Raspi. I had a Bluetooth enabled keyboard(which included a trackpad), so I plugged in the USB that allowed the Bluetooth connection to the Raspi. Additionally, I used the Micro HDMI cable to connect the Raspi to one of the HDMI ports on my TV. Finally, I plugged in the USB-C power supply and booted it up.

Once my Raspi was powered on, I was directed to set it up and change a few settings, which included setting my timezone, connecting to WiFi, and updating it’s software. Additionally, at this point I decided to alter the settings so that the Raspi booted in command line, meaning that I was getting rid of the GUI. I did this because a) I simply didn’t have a need for the GUI, and b) using the GUI took more RAM. In order to do so, I navigated to the terminal, which was located on the upper-left hand of the desktop, and entered sudo raspi-config

This brought me to the software configuration tool. From there I navigated to System Options>Boot/Auto Login>Console. It brought me back to the main page, after which I hit “Finish”, and rebooted the Raspi. Once that was done, the GUI was gone and I was left with only the command line.

Setting Up The External Hard Drive

Because I had a brand new SSD, I needed to give it a file system before I could store anything on it. There were a few file systems I could have chosen, but ultimately I went with exFAT. You can read about different file systems here!

At first I tried to do this from the Raspi command line, but I was running into numerous errors, so I realized that it would be easier to configure it on my laptop. I unplugged the SSD from the Raspi and plugged it into my MacOS. Since it was new, my laptop said it wasn’t recognized, and gave me the option to “initialize”. From there, I navigated to “Erase” and gave it an exFAT file system. Once that was done, I removed the disk from my laptop and put it back into the Raspi.

On the Raspi CL, I entered sudo apt-get update, and sudo apt install exfat-fuse. This allowed me to install the package required. To make sure that I did everything mentioned above correctly, I ran sudo blkid, which gave me information about the “LABEL”, “UUID”, “TYPE”, and “PARTUUID” for each disk partition. Once I saw that the “TYPE” of the hard drive, which I was able to identify because I had named it when it was plugged into my computer, was “exfat”, I knew that things had gone smoothly.

Once that was confirmed, I needed to mount the hard drive to the Raspi. To do so, I needed to know the name of the disk partition mentioned earlier. The name of the disk partition that I wanted to mount was “/dev/sda2”. While I could have mounted the disk partition temporarily, meaning it would unmount when the Raspi rebooted, I wanted to do it permanently, meaning that it would mount again every time the Raspi rebooted.

Before I set that up, however, I needed to create a mount point. I created a folder “data” within a folder “mnt” using a simple mkdir /mnt/data.

To do so, I had to edit the /etc/fstab(filesystem table) file. I entered sudo nano /etc/fstab into the terminal to do so. Underneath the two default entries, I entered a new one: UUID=<UUID> /mnt/data <TYPE> defaults,auto,users,rw,nofail 0 0. I got both the “UUID” and the “TYPE” values using the sudo blkid command. I could have also used the “PARTUUID”, but that was longer so I went with “UUID”. With that done, I saved the changes to the file and rebooted the Raspi. In order to make sure that everything was working properly, I ran sudo lsblk -o MOUNTPOINT, LABEL. I checked to make sure that the “MOUNTPOINT” value of my SSD was “/mnt/data.”

Enabling SSH

At this point I realized that it would be easiest for me to proceed remotely by enabling Secure Shell Protocol(SSH). Enabling SSH would allow me to use the Raspi from my computer. The first thing I needed to do was enable SSH from my Raspi. To do so, I ran sudo raspi-config again to reach the settings page. I navigated to Interface Options>SSH and enabled it from there. It should be noted that you can only use SSH here if both your Raspberry Pi and computer are on the same network.

I simply entered ssh <Raspberry Pi login>@<IP address> from my laptop, entered the password, and I was in. Once you enable SSH, it’s important to change your password from the default(“raspberry”), to a stronger password in order to protect the Raspi from attacks.

Note: For the rest of this article I will be working on my laptop using SSH.

Installing & Running The Bitcoin Core

Now that I had everything else set up, I needed to download the Bitcoin Core. In order to do so I went to the Bitcoin Core Download page and copied the link for “ARM Linux.” Then, I ran wget <link> which allowed me to retrieve the content from the server. In order to install it, I ran tar xvf bitcoin-<version>-arm-linux-gnueabihf.tar.gz, and then sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-<version>/bin/*. The latest version when I installed the bitcoin core was “0.21.1”.

Now that I had it installed, I needed to run the Bitcoin daemon. A daemon is a program that runs as a background process, usually for extended periods of time. I ran bitcoind -daemon --datadir=/mnt/data, and it returned the “Bitcoin Core starting”, which meant that it worked! From there, I found two useful commands which allowed me to track progress.

The first one, which I ran from the root directory, was the following: bitcoin-cli -getinfo -datadir=/mnt/data

“blocks” tells me how many blocks it has downloaded so far, while headers tells me the total number of blocks the Raspi needs to download.

The second allows me to monitor the debug.log file. This one is run in the /mnt/data folder: tail -n 50 -f debug.log

Downloading the blockchain takes a significant amount of time, which varies depending on network bandwidth and machine. Mine took around a week.

Downloading & Setting Up Tor(The Onion Network)

Note: this step can be done while the blockchain is still downloading.

I decided to download Tor so that I could keep my IP address secure. Usually, the Raspberry Pi would be connected directly to the other nodes, but with the Tor network, your data doesn’t arrive to the other nodes directly. Instead, it goes through multiple locations in the Tor network, with each location removing a layer of encryption from the data.

In order to download Tor, I ran sudo apt install tor from the root directory. In order to make sure that it installed properly, I also ran tor --version. Next, I needed to modify the torrc file. The torrc file path for linux is /etc/tor/torrc, so I ran sudo nano /etc/tor/torrc. I then appended the following to the end of the file:

ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1

Now, I needed to figure out the user the bitcoin core was running as. In order to do so, I ran ps -eo user,group,comm |egrep ‘bitcoind|bitcoin-qt’ |awk ‘{print “Bitcoin user: “ $1}’, which returned “Bitcoin user: pi”. Next, I needed to figure out the Tor group, which I did by running getent group | cut -d: -f1 | grep -i tor. This one returned “debian-tor”.

I then ran the following command from the root directory to add the user to the Tor group: sudo usermod -a -G debian-tor pi.

The next thing I needed to do was write to the bitcoin.conf file. The bitcoin.conf is not created automatically, and so I had to make it myself. First, I ran cd /mnt/data, since this is where the bitcoin.conf file should be created in Linux. Then, I ran sudo nano bitcoin.conf to create the file and open it up for me to edit. I then wrote the following to the file:

proxy=127.0.0.1:9050
listen=1
bind=127.0.0.1

I then rebooted my Raspi, restarted the daemon, and ran tail -n 50 -f debug.log from /mnt/data. While it was starting up, I saw a line which said “tor: Got service ID __________, advertising service __________.onion:8333”. With that, I was sure that it was certain that everything was working as it should.

While I was waiting for the blockchain to download, I made sure that my node was properly connected to the network by entering my onion address, “____.onion”, in this website along with the correct port. It returned confirmation that my node was working properly.

Conclusions

I had a lot of fun working on this project and learned about:

  • Raspberry Pi basics
  • Configuring hard drives
  • Mounting hard drives
  • Setting up SSH
  • Tor

I hope this helps you set up your own Bitcoin node!

About Me

Ishaana Misra is a high-schooler interested in AI, Medicine, and Blockchain.

Twitter: https://twitter.com/IshaanaMisra

Check out my newsletters: https://ishaana.substack.com

--

--

Ishaana Misra
Ishaana Misra

Written by Ishaana Misra

Student at Stuyvesant learning about cryptography and Bitcoin.

Responses (1)