...

/

Ethereum Clients

Ethereum Clients

Learn about the role of nodes and clients in Ethereum.

So far, we've primarily focused on how to write Solidity code, but now we'll take a deeper look into how Ethereum works. In this chapter, we'll first learn how to interact with an Ethereum network programmatically, how to write code that can deploy contracts, call methods on them, get information about the network, and more. This will allow us to write applications that are built on top of the Ethereum network, which is an important skill to have for anyone who wants to become a proficient Ethereum developer.

We'll then put theory into practice and write two scripts in JavaScript: one to programmatically deploy the NameService smart contract we created in the previous chapter and the other to send transactions and call methods on the deployed smart contract. We'll also cover some other topics we'll need along the way, for example, how to use the Solidity compiler.

Nodes and clients

Before we look into how to interact with an Ethereum network, we need to learn more about how it's organized and some of its terminology that we'll use throughout the course.

To interact with an Ethereum network, e.g., to send a transaction or deploy a smart contract, we need to send an API request to one of the Ethereum nodes. An Ethereum node is any computer that runs an Ethereum client, which is another word for Ethereum software. All operations with a network are done through this API, such as deploying contracts and calling methods.

An Ethereum network is essentially a web of interconnected Ethereum clients that are accepting transactions, propagating transactions to their peers, and validating and propagating new blocks. Each Ethereum node stores a state of the network, but a node state can be different from the network state in other nodes if it hasn't downloaded recent blocks yet.

Ethereum is a network of interconnected clients
Ethereum is a network of interconnected clients

In contrast to the client-server model, there are no servers here! The network consists of equal peer-to-peer clients connected to each other.

Two client types

Previously, we only had to run a single Ethereum client on a computer to get a functioning Ethereum node. However, after the Merge, a major Ethereum upgrade in 2022, we need to run two clients of different types on a single computer.

The two types of Ethereum clients are:

  • Execution client: This listens to new transactions and blocks and stores the current state of the Ethereum network.

  • Consensus client: This implements the proof-of-stake consensus algorithms that allow a network of decentralized clients to agree on the common network state.

Execution and consensus clients in Ethereum
Execution and consensus clients in Ethereum

To run an Ethereum node, we have to run both types of clients on one computer and connect them. These clients provide an API that can be called from a client library. Both clients interact with each other and with clients running on other Ethereum nodes.

Clients diversity

There's no single implementation for either of these client types. Instead, Ethereum defines two specifications, one for each type of client. Different teams have developed their own implementations of these specifications, but all of them are interoperable with each other.

As of this writing, the most popular execution client is Geth, implemented in Go, but other popular execution clients, such as Parity, are implemented in Rust. For the consensus client, the most popular client is Prysm, also implemented in Go, but there are also other popular clients, like Lighthouse.

But why do we need so many client implementations? Wouldn't it be more efficient to have a single team building a single client of each type?

While that might be more efficient, Ethereum developers decided to have multiple implementations of each client type to ensure that the network is more robust against potential attacks. If there were only one client implementation, a severe bug discovered in it could be used to attack all client instances, which could potentially bring the whole network down.

Having multiple client implementations allows for defending against this scenario. Even if there's a bug in one implementation, it can't be used to target all the nodes on the network.

Running an Ethereum node

But how do we get a node to connect to? One option is to run a node ourselves. We can download an implementation of each client type and run it on our machine. We'd have to configure both clients and connect them to work together. Then, we'd need to manage our node and update clients from time to time when new versions were released. While this option gives us the most control, it's also the most work- and resource-intensive.

An alternative that we'll use in this course is a node service, which is a company that runs a configured Ethereum node for us. While most node services might require a subscription fee, we can use some of them for free as long as we don’t send many requests.

There are a lot of node services to select from. In this course, we'll use Infura, which is one of the most popular. It's also used by the MetaMask plug-in to interact with an Ethereum network.

Regardless of what option we choose, we'll get a URL that we can use to send API requests. When we're writing applications that interact with an Ethereum network, we don’t need to do anything special if we use a node provider. The same code would work with our node as well.

Summary

In this lesson, we learned more about how an Ethereum network works and the role of Ethereum nodes. We learned that to run a node, we need to download and configure a pair of Ethereum clients, or we can use one of the node services, like Infura. In the following lessons of this chapter, we'll learn more about the Ethereum API, how it works, and how to use it, and we'll see how we can interact with an Ethereum network programmatically.

Access this course and 1200+ top-rated courses and projects.