How to run a Linea Mainnet node on a Raspberry Pi 4

Run your Linea node at home using a Raspberry Pi 4 8GB

Running your own Linea Mainnet node at home is a great way to help decentralize the blockchain. Your node also allows you to query the blockchain. You no longer have to trust a third party node.

This step-by-step guide will help you setup your Linea node on a Raspberry Pi 4 8GB with an external SSD. I used a Samsung T7 2TB SSD.

Requirements:

·   Raspberry Pi 4 with 8GB ram

·   External 5V power supply

·   MicroSD card with a minimum of 8gb

·   External SSD drive

·   Access to your router to open ports

·   Stable internet connection, ethernet preferred (+100Mbps)

Step 1: Router config:

Login to your router and open port 30303 for both UTP and TCP. This port needs to open so the Linea node can communicate with other nodes in the network.

Step 2: Booting from USB:

·   Download the Raspberry Pi Imager software for your device, install and open it.

·   Connect the SD card to your computer.

·   Click the ‘Choose OS’ button and select Misc Utility Images -> Bootloader -> USB boot.

·   Click the ‘Choose storage button’ and select your SD card.

·   Click write and wait for the process to complete. The SD card will be ejected automatically.

·   Insert the SD card into the Raspberry Pi and power it on.

·   Wait a few minutes until the Raspberry Pi shows a steadily blinking green light. This means the USB bootloader has been flashed onto the Pi successfully.

·   Power-off the Raspberry Pi and remove the microSD card.

Step 3: Install the OS on the SD card:

In step 2 we enabled USB boot on the Pi. Step 3 will allow us to make some changes to the configuration files.

·   Start the Raspberry Pi Imager tool.

·   Connect the SD card to your computer.

·   Click the ‘Choose OS’ button and select ‘Raspberry Pi OS 64-bit (lite)’ from the menu.

·   Click the ‘Choose storage button’ and select your SD card.

·   (optional) You can set a custom username, password + WiFi settings by clicking the gearbox icon in the right hand corner.

·   Click write and wait for the process to complete. The SD card will be ejected automatically.

·   Create a new, blank, file on your hard drive and name it ‘ssh’, without any extension. This allows us to enable SSH login on the Pi.

·   Connect the SD card to your computer again

·   Copy the new ssh file to the root folder of your SD card.

·   Eject the SD card properly.

·   Insert the SD card into the Raspberry Pi and power it on.

Step 4: IP address and SSH login:

Getting your Raspberry Pi’s IP address is pretty straightforward. Log in to your router and check for ‘Connected devices’. The Raspberry Pi 4 should show up. Copy the IP address.

Make sure you have the correct username/password combination you set in step 3. If you didn’t specify a custom username/password, the default Pi login credentials are:

●   Username: pi

●   Password: raspberry

Launch your terminal (MacOS) or command prompt (Windows) and login.

ssh username@YOUR_PI_IP_ADDRESS (for example ssh pi@192.168.0.213)

Step 5: Update, upgrade and configure:

First, we’ll want to update our Pi OS.

sudo apt update -y

sudo apt full-upgrade -y

Wait for these processes to complete.Now we will change our configuration file.

sudo nano config.txt

You’ll open an empty config file. Add this line:

program_usb_boot_mode=1

Press CTRL + X to exit, confirm with Y to save and press enter. Reboot the Pi so the changes in the configuration are enabled.

sudo reboot

After approximately 3 minutes, use your SSH command again to log in to the Pi. After that, shut down the Pi.

sudo shutdown

Wait 2 minutes, power off the Pi and remove the SD card.

Step 6: Remove fingerprints:

In this step we’ll install the Raspberry Pi OS on our SSD drive. First, we’ll need to make sure we don’t run into the infamous ‘fingerprint’ error.

Openbridge.com has a good article on how to fix this.

On macOS, open your terminal and run

sudo nano ~/.ssh/known_hosts

Use your local password to login.

Make sure to remove the entries that are prefixed with your Pi’s IP address. Press CTRL + X to exit, confirm with Y to save and press enter.

Step 7: SSD drive:

Now we can install the OS on our SSD and connect it to the Pi.

●  Connect the SSD drive to your computer

●  Open the Raspberry Pi Imager software

●  Click the ‘Choose OS’ button, then click ‘Raspberry PI OS (other)’ and select ‘Raspberry Pi OS Lite 64-bit’ from the menu.

●  Click the ‘Choose storage button’ and select your SSD drive.

●  (optional) You can set a custom username, password + WiFi settings by clicking the gearbox icon in the right hand corner.

●  Click ‘Write’ and wait for the process to complete. The SSD drive will be ejected automatically.

●  Connect the SSD drive to your Pi and power it on.

●  SSH into the Pi again

●  Check if the Pi uses your SSD drive by using `df -h` in your terminal. I used a 2TB SDD drive for this guide, so the available disk space shows as 1.8T (TB) on the /dev/root/ line.

Available disk space on the SSD is 1.8 TB.
Available disk space on the SSD is 1.8 TB.

Step 8: Node runner:

In order to get our node up and running, we’ll need to install:

●  Git

●  Go (Go is a requirement for Geth (Go Ethereum))

●  Geth (the node sofware)

Let’s get started.

Install Git:

sudo apt install git and confirm.

Install Go:

Download the latest stable Go release. In this guide I used version 1.21.1. See this link to check for newer releases. Make sure you select the Linux ARM64 build.

wget https://go.dev/dl/go1.22.3.linux-arm64.tar.gz

Unpack the file, make sure to change the build number if you downloaded another build from the Go website.

tar -xzf go1.22.3.linux-arm64.tar.gz

Move the Folder to /usr/local/:

sudo mv go /usr/local/

Add /usr/local/go/bin to the PATH:

export PATH=$PATH:/usr/local/go/bin

Install Geth:

Important update May 2024: Linea currently supports Geth version < 14.The latest stable Geth release you should use is 1.13.15.

Get the latest stable Linux download (ARM) from https://geth.ethereum.org/downloads. You can copy the download link and paste it in your terminal, make sure to prefix with ‘wget’.

In this guide I used Geth build 1.13.15.

wget https://gethstore.blob.core.windows.net/builds/geth-linux-arm64-1.13.15-c5ba367e.tar.gz

tar -xzf geth-linux-arm64-1.13.15-c5ba367e.tar.gz

Download the Linea genesis JSON file. This file contains the Linea configuration details.

wget https://docs.linea.build/files/geth/mainnet/genesis.json

Navigate to the Geth Linux folder.

cd geth-linux-arm64-1.13.15-c5ba367e

Link Geth to /usr/local/bin.

sudo cp geth /usr/local/bin

Go back to the Pi root.

cd ..

Check if Geth has been installed successfully.

geth version

Now we need to map the Linea genesis JSON file to our Geth data directory, so Geth knows which file (settings) to use when Geth is launched.

geth --datadir ./geth-linea-data init ./genesis.json

Good job, we’re almost ready to launch Geth.

By default, our SSH terminal will kill any running processes when the terminal is closed. We want our node to continue, even after we close the terminal. Let’s install a nice little tool called ‘Screen’.

sudo apt-get install screen

Using the screen command will open up a new terminal window. Pressing space bar allows you to enter commands as usual.

Our Raspberry Pi is now ready to start our Linea Geth node.

Run this command from the root (make sure you are in the same terminal tab/window as where you just entered the screen command).Important note: replace the '127.0.0.1' http address on line 11 with your node’s IP address and remove the '', like so:

--http.addr 192.168.0.213

Doing so allows us to connect MetaMask to our node (see step 10).

geth \
--datadir $HOME/geth-linea-data \
--networkid 59144 \
--rpc.allow-unprotected-txs \
--txpool.accountqueue 50000 \
--txpool.globalqueue 50000 \
--txpool.globalslots 50000 \
--txpool.pricelimit 1000000 \
--txpool.pricebump 1 \
--txpool.nolocals \
--http --http.addr '127.0.0.1' --http.port 8545 --http.corsdomain '*' --http.api 'web3,eth,txpool,net' --http.vhosts='*' \
--ws --ws.addr '127.0.0.1' --ws.port 8546 --ws.origins '*' --ws.api 'web3,eth,txpool,net' \
--bootnodes "enode://ca2f06aa93728e2883ff02b0c2076329e475fe667a48035b4f77711ea41a73cf6cb2ff232804c49538ad77794185d83295b57ddd2be79eefc50a9dd5c48bbb2e@3.23.106.165:30303,enode://eef91d714494a1ceb6e06e5ce96fe5d7d25d3701b2d2e68c042b33d5fa0e4bf134116e06947b3f40b0f22db08f104504dd2e5c790d8bcbb6bfb1b7f4f85313ec@3.133.179.213:30303,enode://cfd472842582c422c7c98b0f2d04c6bf21d1afb2c767f72b032f7ea89c03a7abdaf4855b7cb2dc9ae7509836064ba8d817572cf7421ba106ac87857836fa1d1b@3.145.12.13:30303" \
--syncmode full \
--metrics \
--verbosity 3

If all goes well, your node will start to look for peers.

The Geth node starts looking for peers.
The Geth node starts looking for peers.

A while later, Geth will start to download Linea blocks.

The Geth node starts importing blocks
The Geth node starts importing blocks

It can take about a day (depending on the current size of the Linea blockchain) to finish syncing all the blocks.You can easily track the process by comparing the latest synced block number to the latest block on the official Linea Explorer.

You can close the terminal and check back on the latest progress by SSHing back into your node. First, list all running ‘screen’ instances.

screen -ls

A summary of the running 'screen' instances
A summary of the running 'screen' instances

Copy the instance name and run

screen -r “INSTANCE_NAME”, like so:

screen -r 4679.pts-0.raspberrypi4

After approximately 24h (at the time of writing), our local node is fully synced with the Linea blockchain.

Congratulations, you now play an important role in decentralizing the network!

You can stop Geth by going into the screen instance and using the CTRL + C command in your terminal.

Stopping the Geth node
Stopping the Geth node

Restarting the Geth node is as easy as using the

geth \ --datadir $HOME/geth-linea-data \…

command again. Make sure to use your node’s IP address on line 11 of the command:

--http.addr 192.168.0.213

Step 9: Use your own node to query the blockchain

We can easily use a curl command to get the ETH balance of an address. This command will return a JSON object that contains the result of our call. In this example, we want to get the ETH balance of address 0x8F81e2E3F8b46467523463835F965fFE476E1c9E.

Let’s open up a new terminal tab first.

curl --data '{"jsonrpc":"2.0","method":"eth_getBalance", "params": ["0x8F81e2E3F8b46467523463835F965fFE476E1c9E", "latest"], "id":2}' -H "Content-Type: application/json" localhost:8545

The terminal immediately returns the result:

{"jsonrpc":"2.0","id":2,"result":"0x5f39a034a34bd33b"}

Use curl to query your Linea node
Use curl to query your Linea node

When we convert 0x5f39a034a34bd33b to a decimal value, we see the ETH balance of the account is 6861691655214061000 wei, or 6,861691655214061 ETH.

Using curl commands can be a bit tedious. Let’s make it a little bit easier by launching the Geth console and use web3.js commands. You can read the Geth documentation about the Javascript console here. Unfortunately, async methods are not supported by the Geth console.

Start the console from the root:

geth attach ./geth-linea-data/geth.ipc

Now let’s get the balance of account 0x8F81e2E3F8b46467523463835F965fFE476E1c9E again, but now with a web3.js call:

eth.getBalance("0x8F81e2E3F8b46467523463835F965fFE476E1c9E");

Running eth.getBalance() in the Geth console.
Running eth.getBalance() in the Geth console.

Get the latest block data:

eth.getBlock("latest");

Running eth.getBlock() in the Geth console.
Running eth.getBlock() in the Geth console.

To exit the Geth console, press ctrl-d or type exit.

Step 10: Connect MetaMask to your node

We can also your use node to broadcast our MetaMask transactions to the network. It’s really nice to sign your transactions without having to trust a third party node.

In MetaMask, go to Settings - Networks - Add Network. A new tab will open in your browser.Click ‘Add a network manually’ on the bottom of the screen.

Add a network in MetaMask
Add a network in MetaMask

Enter the requested details in the next screen, make sure to enter your node’s IP address.Don’t mind the remark concerning the Chain ID.Click save when you entered all the correct details.

Add a custom network in MetaMask.
Add a custom network in MetaMask.

Great, you connected MetaMask to your local node! Congratulations! You are a real decentraliz00r and you can now sign your transactions through your own node. Don’t forget to switch back to the regular Linea Network when you’re not at home ;-).

Did you enjoy this guide? Feel free to mint the NFT!

Useful links:

Subscribe to Pieter
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.