How to Farm Chia with a Raspberry Pi

In this tutorial, we will be showing you how to farm the Chia coin with a Raspberry Pi.

Raspberry Pi Chia Farmer

One of the cool things about Chia is that we can use a Raspberry Pi to farm the coins on a pre-plotted hard drive because it doesn’t rely on having lots of processing power.

If you are interested in how exactly this works, you can read the Chia green paper that explains how exactly all of this is meant to work.

One of the cool things about Chia is that we can use a Raspberry Pi to farm the coins on a pre-plotted hard drive. This is because Chia doesn’t require a considerable amount of processing power.

Thanks to its low power consumption, a Raspberry Pi to farm Chia coins is a great choice. You can keep your Pi farming your Chia plots without having to stress about the amount of power you are using.

Before proceeding further with this guide, you will need an external hard drive that has already been plotted. Unfortunately, the Pi isn’t quite powerful enough to create plots, so we won’t be covering that in this guide.

For this guide, we will be focusing on setting Chia up for a headless setup. This means all you need is SSH access to your device.

Equipment

Below is the list of equipment we used when setting up Chia on our Raspberry Pi.

Recommended

Raspberry Pi 4

Micro SD Card

Power Supply

Network Connection

External Hard drive or USB Drive

Optional

Raspberry Pi Case

Keyboard

Mouse

We tested running the Chia blockchain on a Raspberry Pi 400 using the 64-Bit version of Raspberry PI OS.

Preparing your Raspberry Pi for Chia

Preparing your Raspberry Pi to act as a Chia farmer is a relatively straightforward process.

There is one big caveat though, we require a 64-bit operating system. This means you will be limited to using a Raspberry Pi 3 or newer. Personally, we recommend that you use a Pi 4.

1. Before continuing, make sure that you are using a 64-bit operating system. The two most popular options are to use the 64-bit beta of Raspberry Pi OS or Ubuntu server.

For our tutorial, we will be using the Raspberry Pi OS 64-bit beta. However, these steps will work for the Ubuntu server as well but will require some slight tweaks.

2. Once you have a 64-bit operating system installed on your Raspberry Pi, we can proceed.

Our first step is to ensure that we have the latest package list and upgrade any out-of-date packages.

We can perform this task by running the following two commands on the system.

sudo apt update
sudo apt upgrade

3. With our Raspberry Pi up to date, we now need to install the packages required to set up the official Chia blockchain.

Use the following command on your system to install the packages we need.

sudo apt install git build-essential python3-dev

With this command, we are installing three different packages. To give you an idea of what they are for, we will quickly run through them now.

  • The first package we install is “git“. We will be using this package to clone the official Chia blockchain code to our Raspberry Pi.
  • Our second package is called “build-essential“. This is actually a meta-package that installs a bunch of compilers that will be used when installing the Chia blockchain Python packages.
  • Our final package is “python3-dev“. This package contains the header files that are required to build Python extensions. These will be needed when installing Chia on your system.

4. Now that we have all the packages we need, we can finally clone the Chia blockchain repository to our Raspberry Pi.

Thanks to installing git in the previous step, we only need to run the command below.

git clone https://github.com/Chia-Network/chia-blockchain.git -b latest

At the end of the command, we use the “-b” argument to select the branch named “latest“. This branch is kept up to date with the code for the latest stable release.

Setting up the Chia Blockchain on your Raspberry Pi

Now that we have the Chia blockchain cloned to our Raspberry Pi, we can now install it. This process is relatively straightforward as the repository we cloned contains everything we need.

1. Our first step is to change into the freshly cloned directory.

We can change into this directory by using the cd command on your device.

cd chia-blockchain

2. We can now run the install script that comes with the Chia repository. This script will check that everything is set up correctly and begin the installation process for Chia.

This mainly involves downloading and building the Python package for Chia.

Run the following command on your Raspberry Pi to begin the Chia install process.

sh ./install.sh

3. Our next step is to change into the new virtual environment created during the Chia installation process.

To switch into the virtual environment, use the following command on your device.

. ./activate

4. Our next step is to initialize Chia on our Raspberry Pi by using the command below.

This command generates some basic things required to secure the connection to the Chia mainnet.

chia init

5. The steps for this last command differ depending on whether you have generated keys for your Chia wallet or not.

If you already have keys generated for Chia, then please follow step a). Alternatively, if you want to generate new keys, you should follow step b).

The Chia key is the unique 24-word phrase you should have created when you plotted your hard drive.

a) At this point if you already have your unique 24 words that make up your private key, you can enter them into your Raspberry Pi Chia farmer.

1. To add your existing keys to Chia, run the following command on your device.

chia keys add

2. After running this command, you will be required to enter the 24-word phrase.

Once entered, you just need to press the ENTER key to confirm the phrase.

b) Alternatively, you can also use your Raspberry Pi to generate a brand new private key for Chia. This process is straightforward and is helpful if you are only just getting started with Chia.

Make sure that you use the phrase generated from this when you want to plot your hard drive.

1. To generate a new private key, all you need to do is run the following command on your Raspberry Pi.

This command will tell Chia that it should create a brand new private key.

chia keys generate

2. After generating your private key, you will probably want to back this up somewhere. As this key gives someone access to your Chia wallet, make sure you never give this out to anyone.

There is no need for anyone to ever have access to this key, and it should only be used when setting up either your Chia farmers or wallet.

To get the mnemic phrase for your keys, you will need to use the following command.

chia keys show --show-mnemonic-seed

The phrase that you are after will be the 24 secret words at the bottom of the output. It is safe to ignore the other keys shown here, as the 24-word phrase is used to generate those keys again.

5. With the keys generated and everything configured, we can finally start the Chia farmer on our Raspberry Pi.

To start the Chia farmer, we need to run the following command.

chia start farmer

Adding a Plot to your Chia Farm

Now that we have the Chia farmer up and running on your Raspberry Pi, we can add a plot to the farm.

1. Before proceeding, you will need an external hard drive connected to your Raspberry Pi that already has plots on it.

While it is possible to use the Pi 4 to plot a hard drive, it is not recommended as it will take considerable time, even for a relatively small plot.

If you haven’t mounted a drive to a Raspberry Pi before, be sure to follow our tutorial on mounting a USB drive.

2. With a drive mounted to your Pi, you will need to work out the location of the plots.

Any drive automatically mounted to your Raspberry Pi should be located within the “/mnt/” directory. You can list the contents of this directory by utilizing the ls command.

ls -l /media/pi/

Identify the drive where you have saved your Chia plots, and make a note of the directory name.

3. Once you have the full path to your Chia plots, we can finally add it to our Raspberry Pi farmer.

All you need to do is use the following command. Make sure that you replace “[DIRECTORY]” with the full path.

chia plots add -d [DIRECTORY]

For example, we used the following command to have our plots mounted to “/media/pi/pimylifeupplots/“.

chia plots add -d /media/pi/pimylifeupplots

4. You can verify that Chia can see your plots by running the following command on your system.

This command will tell Chia that it should check and verify the validity of your plots.

chia plots check

This process can take some time, depending on the number of plots on your hard drives. You should eventually see a message similar to the one we have below.

chia.plotting.check_plots        : INFO     Summary
chia.plotting.check_plots        : INFO     Found 1 valid plots, total size 0.09898 TiB
chia.plotting.check_plots        : INFO     1 plots of size 32

Starting Chia when your Raspberry Pi Boots

Now that you have a Chia farmer up and running on your Raspberry Pi, you will now likely want it to start on bootup.

To get Chia to start on boot, we will need to create a system file that will handle it.

1. Let us begin writing our new service by running the following command on your device.

We are using the nano text editor as it is relatively easy to use.

sudo nano /etc/systemd/system/chiafarmer.service

2. Within this file, we need to enter the following lines of text. These lines define our service and how we want to start and stop our Chia farmer on our Raspberry Pi.

[Unit]
Description=Chia Farmer
Wants=network-online.target
After=network.target network-online.target
StartLimitIntervalSec=0

[Service]
Type=forking
Restart=always
RestartSec=1
User=pi

Environment=PATH=/home/pi/chia-blockchain/venv/bin:${PATH}
ExecStart=/usr/bin/env chia start farmer -r
ExecStop=/usr/bin/env chia stop all -d

[Install]
WantedBy=multi-user.target

3. Once you have finished writing this file, you can save it by pressing CTRL + X, then Y, followed by the ENTER key.

4. With the service now created, we can enable it by running the following command.

By enabling the service, it will be automatically started when our service.

sudo systemctl enable chiafarmer

5. If you are still running Chia from earlier in this guide, we should stop the currently running nodes. The reason for this is that it could cause issues when we start up our service in the next step

You can kill all currently running Chia processes by running the following command.

chia stop all -d

6. To start up our new Chia service, we need to use the command below.

By using the command below, the service will start up the Chia farmer on our Pi.

sudo systemctl start chiafarmer

7. You can check that Chia has been successfully started on your Raspberry Pi by using the following command.

This command will retrieve the current status of the service.

sudo systemctl status chiafarmer

If everything has worked correctly, you should see the status marked as “Active: active (running)“.

Checking the Status of Chia on the Raspberry Pi

You may want to check on the status of your Chia farm from time to time. The following steps will show you you can do this using the command line.

1. We need to make sure that we are in our Chia blockchain virtual environment. To do this, first change into the repository we cloned earlier in the guide.

Run the following command on your device to change into the directory we cloned.

cd ~/chia-blockchain/

2. Now, run the following command on your Raspberry Pi to activate the virtual environment.

We need to be in this environment to run the Chia commands.

. ./activate

3. As we are now in the virtual environment, we can finally make some Chia calls to check the status of your farm.

The first command we are going to use will give you a status update of the Chia node running on your Raspberry Pi.

This command will tell you the status of the blockchain, the estimated network space, and other information, such as what nodes you are currently connected to.

chia show -s -c

In the screenshot below, you can see that our node is still currently syncing with the rest of the Chia mainnet.

Raspberry Pi Chia Blockchain - Showing Node Status

4. We can also check on the status of the Chia plots that our Raspberry Pi is farming. This will let you know the number and size of the plots your Pi is handling.

You can also use this to check the status of the farm and the number of Chia coins that you have farmed.

Run the following command to get a summary of your farm.

chia farm summary

Below you can see the summary that was outputted to our command line. You can see that our Chia node is still synchronizing.

Raspberry Pi Chia Farm Summary

Updating your Chia Farmer

Like most cryptocurrencies, Chia is always being updated and worked on. Therefore, you will want to make sure that you are using the latest available version of Chia from time to time.

The following steps will show you how to update the Chia farmer running on your Raspberry Pi.

1. First, we need to stop any currently running session of Chia as we are about to update its file.

If you are using our service, this is as straightforward as running the following command.

sudo systemctl stop chiafarmer

2. With the Chia farmer now stopped, we can move on to updating everything.

To start this process, we need to first change back into the directory where we cloned the Chia blockchain code.

cd ~/chia-blockchain

3. We now can use git to update the repository to the latest version.

The command we need to use is called “pull“. It will ensure that we have the latest version of the code from the repository.

git pull

If you see the text “Already up to date.” you can skip to step 7 as you already have the latest version.

4. If you received a new update, we will need to runa few commands to update everything.

The first thing we need to do is run the install script. This script will update the Chia Python packages to their latest version.

sh install.sh

5. Next, we need to re-enable the virtual environment that came with the Chia repository.

To do that, you just need to run the following command.

. ./activate

6. Our next step is to re-run the Chia initialize command.

This command will migrate any Chia files that require an upgrade to the latest available version.

chia init

7. With everything done, we can finally start the Chia farmer back up on our Raspberry Pi.

If you are using the service, we created earlier in this guide, this is as simple as running the following command.

sudo systemctl start chiafarmer

Conclusion

Throughout this tutorial, you will have learned how to set your Raspberry Pi up as a Chia farmer.

The Pi works as a perfect Chia farmer as it has enough resources to maintain the plots while consuming a relatively low amount of power.

If you have had any issues getting Chia set up on your Raspberry Pi, please leave a comment below.

If this tutorial helped you out, be sure to check out some of our other Raspberry Pi projects.

Leave a Reply

Your email address will not be published. Required fields are marked *