Build Your Own Raspberry Pi Ethereum Full Node [Python Client]

Click Here for building the Go client



LAST UPDATED DECEMBER 5, 2015
Disclaimer: I cannot guarantee these steps will work 100% of the time. Like all DIY tutorials they make assumptions about things and are subject to external libraries and software being updated or changed. I periodically test and update these steps for changes or additions, but I can't guarantee that some troubleshooting won't be needed to get your node up and running.

PRELIMINARIES

This tutorial is to install the Ethereum PyEthApp client on a Raspberry Pi 2. Options will be given to store the blockchain data on the microSD card or on an external USB device. EthDev maintains three Ethereum clients: Eth (written in C++), Pyeth (written in Python), and Geth (written in Go). This tutorial is to install PyEthApp, a simple to run instantiation of the Pyeth client. Ethereum is extremely cutting edge and under rapid development, so expect a bumpy ride and some problems if you dive in at this point.

If you run into any Raspberry Pi problems while going through these steps, the Raspberry Pi Docs are a good source for help:

http://www.raspberrypi.org/documentation/

ALTERNATIVES

EthDev has a prebuilt OS image for the Raspberry Pi using ArchLinux. They also have DIY steps for the ArchLinux OS. It comes with both Geth (the Go client) and Eth (the C++ client) preinstalled. You can also download and run pre-built ARM binaries of Geth from here: https://build.ethdev.com/builds/ARM%20Go%20develop%20branch/geth-ARM-latest.tar.bz2 but they are builds from the latest development branch so are not guaranteed to be stable. But they will be up-to-date!

EthEmbedded provides ARM builds for Ethereum for microcomputers such as Raspberry Pi, Odroid, and BeagleBone Black. They have Eth and Geth Install Scripts on github for the Raspberry Pi, the Geth script requiring an upgrade to Debian Stretch rather than using the officially supported Debian Wheezy or Jessie.

FULL STEPS

EQUIPMENT FOR NODE

As of December 5, 2015 the blockchain and data takes up around 8GB of space. Pyeth uses LevelDB to store the blockchain like Bitcoin, and this method takes up more space than the methods used by the Go and C++ clients. With a large microSD card an external storage device is not needed yet, but it may be a good idea to use one anyway.

PURCHASE OPTIONS

You can find what is needed to build an Ethereum raspnode for less than $100.

The CanaKit Raspberry Pi Starter Kit costs $70 (plus tax and shipping) and comes with everything you need minus the USB drive and Ethernet cable (if you wish to cable directly to your router).

With enough exploring, reasonably priced 128GB USB drives can be found, some in the $35 to $40 range. Some 500GB external HDs can be found in the $50 to $60 range.

EQUIPMENT FOR SETUP

ASSEMBLY

How to assemble your Raspberry Pi will depend on the case purchased. Once assembled, plug in your USB stick (optional), HDMI cable to your monitor, USB keyboard, and either your USB Wifi adapter or an Ethernet cable going to your router.

The device will automatically power on once you plug in the micro USB power cable.

INSTALLING THE RASPBIAN OS

If your Raspberry Pi came with a microSD card preloaded with NOOBS you can insert the microSD card into your Raspberry Pi, plug in your power cable and it will walk you through your setup. Make sure you select Raspbian as your OS choice, which should be the first on the list. It will take a few minutes to install. Once that is finished, reboot and jump to Raspbian config options.

If you have a brand new microSD card, you will need to download a Raspbian image to your PC and image your microSD card. This tutorial will assume you are using a PC running Microsoft Windows. Instructions for imaging using Mac or Linux can be found in the Raspberry Pi documents:

http://www.raspberrypi.org/documentation/installation/installing-images/README.md

You can find the latest on the Raspberry Pi downloads page:

http://www.raspberrypi.org/downloads/

Or directly download the latest here:

http://downloads.raspberrypi.org/raspbian_latest

Once downloaded, unzip the file. If you don't have an application installed for unzipping files, you can use the open source 7zip:

http://www.7-zip.org/

The unzipped folder will have a large .img file. In order to put this image on your microSD card we'll need to use the open source Win32DiskImager which can be found on sourceforge:

http://sourceforge.net/projects/win32diskimager/

Or directly download the latest here:

http://sourceforge.net/projects/win32diskimager/files/latest/download

Once downloaded run the installer, this will install Win32DiskImager.

Insert your microSD card into your PC. Launch Win32DiskImager. Select the Raspbian .img file as the 'image file' and select your microSD card as your 'device'. Make sure what is selected is your microSD card and nothing else, especially your hard drive. Click 'write'. This will take a few minutes.

Once finished, eject your microSD card. Insert your microSD card into your Raspberry Pi and plug in the power cable and wait while it boots up.

RASPBIAN CONFIG OPTIONS

When you first boot Raspbian you will be prompted with the raspi-config menu shown below:

If you used NOOBS to install Raspbian your file system will already be expanded to fill your full microSD card. However if you installed a Raspbian image you'll need to expand it now.

Select “1 Expand File System" which will expand the file system to fill the card.

OPTIONAL

You can run your OS 'headless' and we can allocate a little more RAM to the CPU.

Select "8 Advanced Options" then select "Memory Split"

Change 64 to 16

Select "OK"

If you want to be able to SSH into your Raspnode, you can enable the SSH server here.

Select "8 Advanced Options" then select "SSH"

Select "Enable"

Change hostname. The default hostname is set to "raspberry". We'll change ours to "raspnode" and the rest of the tutorial will assume this. If you leave yours as "raspberry" or change it to something else, anytime you see the hostname mentioned, use that instead of "raspnode".

Select "8 Advanced Options" then select "Hostname"

Edit the hostname to “raspnode" without quotes (or to your desired hostname)

Select "OK"

Here you can also change the default user (which is "pi") and password (which is "raspberry"). We'll leave these as is for the tutorial. If you change your username, make sure to use that instead of "pi" when it shows up in this tutorial.

You can overclock your Raspberry Pi in order to give it a little more processing power. This may make the initial verification of the blockchain quicker, but is not needed for normal full node operations.

Select "7 Overclock"

Choose the desired level of overclocking

Select "OK"

To set your timezone:

Select "4 Internationalisation Options"

Select "Change Timezone"

Go through the selection process to select your timezone, then select "OK"

Once done, select "Finished" and your Raspberry Pi will reboot.

When you get the "login" prompt, enter your username "pi" and it will prompt you for your password. Enter your password (which won't show up) and hit <enter> to log in (the password will be "raspberry" if you didn't change it in the raspi-config).

EDITING FILES

We'll be using the command line to edit files. If you are not familiar with a command line this may be a little tricky. Raspbian comes with a few editors. Nano is a relatively friendly editor and this tutorial will use that, but Raspbian also has vi for users who prefer it and can be used instead. If you have not used vi before, you should stick with nano.

For those not familiar with Linux, some actions we take will require root privileges. We get that by using the command “sudo" before our desired command. This will only work if you are logged in as a user with sudo rights, which the default Raspbian user (“pi" in our case) has. Sudo can be set to require a password, but the default Raspbian user should be set to not need one.

You may want to change the default keyboard layout. Edit /etc/default/keyboard

pi@raspnode~$ sudo nano /etc/default/keyboard

Change the line

XKBLAYOUT="gb"

to equal your desired country code, so for US keyboard layout change it to

XKBLAYOUT="us"

Then save and exit. Reboot to have it take effect. Reboot with

pi@raspnode~$ sudo shutdown -r now

CONFIGURE USB AND SET AUTOMOUNT (OPTIONAL)

If you aren't using any external storage you can skip this section and go to networking.

Make sure your USB stick is empty and using a file format that works natively with Linux (e.g. not NTFS). FAT32 is a good option. You can do this by plugging your USB stick into your Windows PC and checking it's properties. If it isn't empty, format it as FAT32. Here you can also change the label. Make a note of the label, it will be helpful later (but not necessary).

Windows may not give the option to format a drive that is very large as FAT32, in which case you will need to use some third party software, or format it in Linux. Also, note that Raspbian will most likely see FAT32 as VFAT which is what we'll see below.

Create a directory that will act as a mount point for the USB stick, we'll call it ethData and put it in the home directory (full path will be /home/pi/ethData/:

pi@raspnode~$ mkdir ~/ethData

Plug your USB stick into your Raspberry Pi and wait a few seconds. In order to see where it is located, issue the command:

pi@raspnode~$ sudo blkid

You can issue the blkid command without sudo, but if you run it without root privileges you won't get any information back. What you should see is a few lines that look something like this:

/dev/mmcblk0p1: LABEL="root" UUID="1460456c-eadd-49a9-e2ab-a0fe18df0d3a" TYPE="ext4"

Which are specific to your OS. What you are looking for is a line like:

/dev/sda1: LABEL="<your usb label>" UUID="<some id>" TYPE="vfat"

This is where knowing your label can help. The type should be “vfat" and you are looking to see what the /dev/sdxx is (it could be sda1, sdb1, or something similar, but most probably sda1). Write that down. You don't actually need the label or uuid written down, just the location.

In order to tell your Raspberry Pi to mount your USB stick automatically so that anything we put in the ethData directory will be going onto the USB and vice versa we need to edit the /etc/fstab file.

pi@raspnode~$ sudo nano /etc/fstab

It should have a few lines of information, at the end of the file add this, all as one line, starting with the location of your USB drive that you wrote down. If it is /dev/sda1, then what you add would be this:

/dev/sda1 /home/pi/ethData vfat uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser 0 0

If you changed your username to something else, replace “pi" with that username above in all areas it shows up. There are no spaces in that line, only a single tab between each chunk of data. There are other options that you could use if you wanted more or less restrictions on your drive, but this will work. You should only alter this setup if you know what you are doing. Basically this will automatically mount the USB drive on boot to our desired location, allow the pi (or substituted user) to read and write data to the drive, and a few other things beyond the scope of this tutorial.

Save the file and exit. Reboot your Raspberry Pi:

pi@raspnode ~ $ sudo shutdown -r now

NETWORKING ON THE RASPBERRY PI

If you are using an Ethernet cable and plugging directly into your router and DHCP is turned on, you can plug that in and you should have access to the Internet. You can check by pinging out:

pi@raspnode~$ ping google.com

If you start to see pings you are good. Hit <ctrl> + c to stop the pings. If you are using a wifi adapter and have a password set for your router, there are a few more steps to take. Setting up and troubleshooting wifi on the Raspberry Pi is beyond the scope of this tutorial, so if the basic setup shown here doesn't work, you can reference the Raspberry Pi documentation for help:

http://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

To setup your wifi, edit the file /etc/wpa_supplicant/wpa_supplicant.conf:

pi@raspnode~$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add this to the bottom of the file:

network={
    ssid="<your wifi ssid here>"
    psk="<your wifi password here>"
}

For example, if your wifi network is named myHomeWifi and your wifi password is mySuperSecret then wpa_supplicant.conf should look something like:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="myHomeWifi"
    psk="mySuperSecret"
}

Then restart your wifi interface:

pi@raspnode~$ sudo ifdown wlan0
pi@raspnode~$ sudo ifup wlan0

If you need to set a static IP, that is currently out of the scope of this tutorial.

DOWNLOADING ETHEREUM PYETH DEPENDENCIES

First let's make sure everything is up to date and update it if it isn't:

pi@raspnode~$ sudo apt-get update
pi@raspnode~$ sudo apt-get upgrade -y

We need to install some dependencies including pip (a python module installer). Running this will download what is needed:

pi@raspnode~$ sudo apt-get install python-pip python-dev -y

INSTALLING PYETHAPP

Unlike the Go or C++ client Pyeth is written in Python so we don't need to compile any source code, making installation very easy:

pi@raspnode~$ sudo pip install pyethapp

PyEthApp also comes with the genesis block, unlike the Go client so we don't need to download that.

RUN PYETHAPP

You can run PyEthApp without any configuration:

pi@raspnode~$ pyethapp run

You will see a bunch of output on the screen, some syncing errors and other peer and network warnings. This may stop and it may seem like nothing is going on. If you leave it be, it will eventually starts syncing and downloading blocks. This process is much slower than the Go client, and it looks like it could take a week or more to sync with the network. I suggest downloading the blockchain using pyethapp on another computer first and transfering it over. It took around 12 hours for my server to sync the full blockchain as of December 2015 using PyEthApp. The default location for the pyethapp blockchain is ~/.config/pyethapp/leveldb.

To have PyEthApp store the blockchain in your external drive, run with the data directory option:

pi@raspnode~$ pyethapp --data-dir /home/pi/ethData/ run

PyEthApp comes bundled with the IPython interactive command prompt, of which I'll go into a little more detail the next time I update this tutorial, as well as basic functions such as creating accounts.

CONFIGURE HOME NETWORK TO SYNC WITH THE ETHEREUM NETWORK

The Ethereum network uses port 30303 by default. You will need to forward that port to allow other nodes to connect to you. To do that you will need to get your raspnode's local IP address with:

pi@raspnode~$ ifconfig

If you are cabled into your router directly the IP address will be under "eth0", if you are on wifi it will be under "wlan0". How to forward ports will be specific to your router and may take some exploring if you are not familiar with networking.