Cover photo

How Ethereum works

Introduction

While this text is about Ethereum, it’s supposed to give you an understanding of programmable blockchains in general, also called Layer 1s (L1s). But we’ll use Ethereum as an example, because well… it’s Ethereum. It still dominates the market even though new L1s claim to be cheaper, faster, more scalable, etc… Once we understand different aspects of Ethereum, we will be able to reason about other programmable blockchains, see what they do differently, and fairly evaluate their claims. But this will be a topic of some other blog posts.

The best audience for this text is engineers with little knowledge about blockchains. However, others may surely find something useful here as well.

What is Ethereum

It’s a computer that can’t be turned off. Because it’s a decentralized computer. It runs on many different machines around the world, and it is specifically designed to allow as many people as possible to participate. A machine running Ethereum is called a node, and there are at least 10,000 Ethereum nodes live at the moment. By the way, you can run one too!

https://ethereum.org/en/run-a-node/

You can build applications on top of Ethereum. Currently, it’s mostly financial applications, because the financial world can truly benefit from properties like openness, inclusivity, and censorship-resistance. They are usually called decentralized apps or dApps.

How can Ethereum run dApps? Each node contains a virtual machine that can execute arbitrary code. Ethereum also has state, a global database of sorts, that can be updated as a result code execution. Ethereum state is updated only when the majority of the nodes agree that code execution is valid (see consensus section for details).

Ethereum Virtual Machine

Ethereum Virtual Machine or EVM has certain limitations. For example, it cannot query data from the outside world. You can’t just call a random API or initiate a connection to an external database. This means if we want to use data from the outside we need to push it to Ethereum. There are different ways to do this securely and there exists a separate class of projects focused on this called oracles.

All transactions to the EVM are initiated by Externally Owned Accounts. An EOA is a public-private key pair where the public key acts as an account address, and the private key is used to sign transactions. It means that to start interacting with Ethereum you just need to generate a random key pair, and then use your private key to create transactions. This is exactly what crypto wallets do when you set up an account.

In order to execute code on Ethereum, it first has to be published and assigned an address. A published piece of code is called a Smart Contract. EOAs can then execute code by sending transactions to the smart contract’s address. Smart contracts can also interact with each other making it possible to build flexible and composable products. A dApp can consist of one or more smart contracts.

Transaction flow (ethereum.org)
Transaction flow (ethereum.org)

Transaction costs

Code execution on Ethereum is expensive. Every node participating in the network has to run every transaction. They also need to store the full Ethereum state increasing by hundreds of gigabytes every year. With these limiting factors, current Ethereum throughput is about 15 transactions per second (tx/s). It would be very easy to spam the network causing denial of service if not for the concept of gas.

Each transaction on Ethereum costs gas which is paid in ETH currency. This is what creates demand for ETH and makes it valuable. The amount of gas one needs to pay depends on the complexity of the code they are running: each operation of the virtual machine has a cost and developers need to be mindful of that when building smart contracts. Compute-intensive applications therefore cannot be built on Ethereum, at least directly using smart contracts.

Gas also costs more in times of high demand. This is because in order to execute transactions users bid a certain price like in an auction. Nodes then execute transactions with higher gas price first.

Consensus

I already mentioned that in order to change the state of Ethereum, the majority of nodes have to agree on the new state. This is called consensus and different blockchains use different algorithms to achieve it. Ethereum uses the most popular type of consensus algorithms called proof-of-stake (PoS).

In proof-of-stake nodes that want to participate in consensus need to stake or lock a certain amount of ETH tokens as insurance against malicious behavior. These type of nodes are called validators. Validators’ job is to verify transactions sent to the network making sure that they don’t produce any invalid state changes. If a validator starts to accept invalid transactions their staked ETH will be slashed incurring financial loss.

This model makes it quite difficult to attack the blockchain. In order to produce invalid state (for example stealing tokens from someone else’s account) one must possess over 50% of all staked ETH which is currently worth over 31 billion dollars.

Ethereum nodes
Ethereum nodes

Interacting with Ethereum

Let’s say you want to transact on Ethereum. To submit a transaction you need to sign it with your private key and send it to one of the nodes. There is a variety you can choose from, for example:

  • One of the public endpoints set up by community.

  • Commercial endpoint from providers like Infura or Alchemy.

  • Your own node running on your server.

Whichever approach you choose the node will then propagate your transaction to all other nodes and once consensus is reached - your transaction will be accepted.

Blockchain wallets like Metamask allow you to configure a custom endpoint so that you can use the one you’re most comfortable with or switch in case the default one goes down.

Signing also usually happens in your crypto wallet but it can also be done

Interacting with Ethereum (ethereum.org)
Interacting with Ethereum (ethereum.org)

dApps on Ethereum

To further help you understand Ethereum and its capabilities let’s introduce some of the projects built on top of it.

USDT

USDT is a token emitted by a real-world company Tether Limited. You can send US dollars to Tether and receive USDT in exchange. Now, using USDT you can settle financial transactions in US dollars on Ethereum.

USDT is just a smart contract that tracks user balances in Ethereum storage. An Ethereum account belonging to Tether Limited has exclusive rights to mint and burn USDT tokens. You can explore USDT’s smart contract including the source code here:

https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#code

Uniswap

Uniswap is a decentralized exchange or a DEX. It allows you to buy and sell assets in a trustless manner. You don’t need to deposit your assets to a centralized entity like Binance. Instead, tokens are exchanged directly in your EOA account.

This is how you can trade ETH for USDT on Uniswap
This is how you can trade ETH for USDT on Uniswap

Aave

Aave is a lending protocol. It allows you to borrow money in exchange for collateral (for example borrow USDT for ETH collateral). On the opposite side, you can earn yield by making your assets available for borrowing.

Earning 5% APY on your USDT on Aave
Earning 5% APY on your USDT on Aave

Mirror

This blog is also a decentralized application. However, it uses more than just Ethereum.

Blog posts on Mirror are stored on Arweave - a decentralized storage protocol. You can use your Ethereum wallet to sign in to the website. And you can also mint a receipt that you’ve read this article and store it on the blockchain. Minting happens on Optimism, which is an Ethereum layer 2 (we’ll get into L2s in the following blog posts).

These receipts can be used in a variety of ways. For example, Mirror can pay content creators based on the amount of receipts their posts get. Or content creators can retroactively reward users who supported them and minted their articles.

Conclusion

Blockchain technology is a vast space and we’ve just scratched the surface. In the following posts, we will go deeper and explore topics like Ethereum L2s, alternative L1s, different types of dApps, and many more. If you want to find out more about Ethereum, there is no better resource than an official website

https://ethereum.org