DEV Community 👩‍💻👨‍💻

Cover image for Setting up an Ethereum Node (Execution Client)
Akim (mousticke.eth)
Akim (mousticke.eth)

Posted on

Setting up an Ethereum Node (Execution Client)

Caveat

It's still possible to run the execution client (layer 1) alone but after the Merge in the upcoming days, we need to run the execution client and consensus client to be able to access to the Ethereum network. In this article, I will cover the execution layer only.
The execution client listens to new transactions and executes them in the EVM (state machine) and holds the database of Ethereum network.

This article covers the node running from the source code or from the package in Ubuntu.


Table Of Contents

Abstract

Little abstract before jumping in our journey with the Ethereum node.
Ethereum is a distributed decentralised network of computers. Each computer in this network is running a software that contains the history of the blockchain, the ability to validate/mine blocks and transactions.
In order to be a node in the Ethereum network, a client needs to download this software that implements the specification of the yellow paper to be able to communicate within the network.
In this article, the client I'll be choosing is Geth. It's the most popular client and backed by the Ethereum Community.


Prerequisites

You can run a node on any computers but it's worth to consider running your Ethereum node in a dedicated hardware to minimise the performance issues.
Make sure to have a stable internet connection. Even though you can go offline, your node goes inactive until you come back and download the latest changes from other nodes automatically.
You can buy hardware from a vendor and have a plug and play node or you can build your own. The last option is cheaper and funnier.

Hardware

Minimum:

  • 8GB RAM (16GB for a validator);
  • 2TB SSD for write speeds (12TB for Archive node);

Recommended:

  • CPU with a benchmark score of 6667+
  • 16GB RAM (32GB for a validator);
  • Unlimited High speed internet bandwidth;

Node types

In order to run your node, you need to be aware of the node types. Each node type consumes data differently. There are 3 node type:

  1. Light Node
  2. Full Node
  3. Archive Node

Light Node

Instead of downloading the entire blockchain, you can download a shallow copy of the data containing only the block headers. A light node relies on a full node to get more data. A light node can also verify the data and participate to the network. The drawback is that you cannot participate in a consensus, you cannot be a miner nor a validator.

Full Node

The full node stores all block data not since the Genesis. This is periodically pruned and get only the most recent 128 blocks. A full node can:

  • Participate in a consensus;
  • Validate blocks;
  • Verify the states;
  • Serve the network and provide data on request;

The drawback is that you cannot query data at block #1,000,000 because you don't have the entire history. Only the 128 last blocks.

Archive Node

The archive node stores the historical states since the Genesis. Basically, if you want the query data since the first block, you can with the archive node.


Why should I run a node?

If you really believe in Ethereum, and decentralised crypto currency, you should consider running a node.

For me

You can use Ethereum privately and verify the data yourself. "Don't trust, verify" is a popular Blockchain mantra.

  • Don't rely on another node
  • Use an Ethereum wallet within the node and use DApps more securely and privately without leaking your address and balance to another node.
  • Build your custom RPC endpoint
  • Stake your ETH and earn rewards (be a validator with 32ETH)
  • Allow wallets provider like Metamask to use your node

For the Network

  • Enforce the consensus rules
  • Social recovery in case of massive attack
  • More diverse and robust network and provide a censorship-resistant ecosystem

Installation

Golang

In order to download the source code, you need to install git command.
geth is a software coded in golang. You need to install Go before.

If you are on Windows and have Chocolatey installed, you can run (Admin mode) these commands:

choco install git
choco install golang
choco install mingw
Enter fullscreen mode Exit fullscreen mode

(If you run these commands, you'll need to close your terminal and open up a new one)

Then you can follow one of these steps in order to have Geth installed:

  • Download Source code (Windows) or
  • Download Source Code (Linux) or
  • Download the Package (Ubuntu)

Download Source code (Windows)

In order to download the source code, you can copy and paste these commands:

mkdir src\github.com\ethereum
git clone git@github.com:ethereum/go-ethereum.git src\github.com\ethereum\go-ethereum
mkdir src\github.com\ethereum\go-ethereum
Enter fullscreen mode Exit fullscreen mode

You should have this output:
Image description

You can now build the project from the binaries

go get -u -v golang.org/x/net/context
go install -v ./cmd/...
Enter fullscreen mode Exit fullscreen mode

Image description

Download Source Code (Linux)

If you have Linux (or MacOS), it's slightly different. You can just run this command:

go get -d github.com/ethereum/go-ethereum
Enter fullscreen mode Exit fullscreen mode

If you have an existing Geth client, you can update with this command

go get -u github.com/ethereum/go-ethereum
Enter fullscreen mode Exit fullscreen mode

Download the Package (Ubuntu)

You need to add the launchpad repository

sudo add-apt-repository -y ppa:ethereum/ethereum
Enter fullscreen mode Exit fullscreen mode

Then you can download the stable version of go-ethereum

sudo apt-get update
sudo apt-get install ethereum
Enter fullscreen mode Exit fullscreen mode

If you have an existing geth installation, you can get the latest version with the following commands:

sudo apt-get update
sudo apt-get install ethereum
sudo apt-get upgrade geth
Enter fullscreen mode Exit fullscreen mode

Create the chaindata folder

In order to store the chain data, you need to create a folder somewhere in your system. I usually create the chain data at the same level of the binary (in my case)

mkdir -p ./chain/data
Enter fullscreen mode Exit fullscreen mode

Image description

Run the node

Now you are ready for running the node.

geth console --syncmode full --networkid 1 --gcmode full --datadir ..\chain\data\
Enter fullscreen mode Exit fullscreen mode

What I'm doing here:

  • geth: command line interface for the client
  • console: start geth environment
  • syncmode full: blockchain sync mode to full (default to snap)
  • networkid 1: run the mainnet (by default it runs the mainnet)
  • gcmode full: Garbage collection (full or archive)
  • datadir: chaindata folder path that I have created earlier on

You can run a testnet node if you want to. You need to remove --networkid 1 and replace by --ropsten or --goerli or kiln or sepolia or rinkeby.

Run geth --help to see the full list of commands

Once you have executed this command, you should have this output

Image description

You will see that it will be searching for peers and download the blockchain data since the genesis (7 years 2 month and 5 days in my case)

Image description

(It's running in foreground. As soon as you close the terminal or press Ctrl+C / Ctrl+D, it will shutdown the node). If you want to run a node in a foreground or using as a service in Ubuntu, there are a lot of documentation for you. This is not the purpose of this article.


Interacting with Geth

You can interact with your node by attaching it to the datadir

geth attach --datadir ..\chain\data\
Enter fullscreen mode Exit fullscreen mode

Image description

You can see what is the current block being downloaded and the highest block by executing this command in the interactive console
eth.syncing

Image description

You can also execute Javascript code. In this example, I execute this snippet to know every 10 seconds the number of blocks per seconds being downloaded, the percentage of data downloaded and the remaining time

var lastPercentage = 0;
var lastBlocksToGo = 0;
var timeInterval = 10000;
setInterval(function(){
    var percentage = eth.syncing.currentBlock/eth.syncing.highestBlock*100;
     var percentagePerTime = percentage - lastPercentage;
     var blocksToGo = eth.syncing.highestBlock - eth.syncing.currentBlock;
     var bps = (lastBlocksToGo - blocksToGo) / (timeInterval / 1000)
     var etas = 100 / percentagePerTime * (timeInterval / 1000)

     var etaM = parseInt(etas/60,10);
     console.log(parseInt(percentage,10)+'% ETA: '+etaM+' minutes @ '+bps+'bps');

     lastPercentage = percentage;lastBlocksToGo = blocksToGo;
 },timeInterval);
Enter fullscreen mode Exit fullscreen mode

Image description

The number of block will be decreasing because over the year, there are more and more transaction in a block and you will be downloading more data in a full node in the last 128 blocks.


Run the node (dev mode / contributor)

The purpose of this article is not to help you running in dev mode. So I won't detail too much.
If you want to contribute to the Ethereum client, you can run the command geth in dev mode without putting your assets at risk. There is a --dev flag that run geth in dev mode. In this way you have a node with:

  • Data directory with a testing genesis block
  • Max peers to 0. That means that Geth won't search for peers (default to 50)
  • The node won't be visible to other nodes
  • Gas price is set at 0 wei
  • PoA (Proof of Authority) in order to mine block on demand
  • Generate Block on demand.

For example, you can run this command:

geth --dev --http --http.api eth,web3,personal,net --http.corsdomain "http://remix.ethereum.org"
Enter fullscreen mode Exit fullscreen mode

(See the full help from the command geth --help)


Next Steps

The next step is to run the consensus layer in order to be able to participate in the network after the merge.
After that, we will be covering the setup of a private node.


Conclusion

Here you have just an overview on how to setup an Ethereum node. There are more to cover like:

  • Using Clef as ab account management for Geth that allows to sign transaction
  • Create a specific user to setup the node and give privilege
  • Port forwarding for your node
  • Miner options from the command line (will be deprecated)
  • Auto start on boot in Linux And more.

Thank you for reading and have fun in the decentralised world :)

Top comments (0)

Stop sifting through your feed.

Find the content you want to see.

Change your feed algorithm by adjusting your experience level and give weights to the tags you follow.