Bitcoin Mining Labby Coinovo

Mining Lab · Coinovo Academy · Ethereum and smart contracts

Ethereum and smart contracts

A shared computer with a fee meter

Intro 10 min 7 cards 18 questions

Objectives

More than a ledger

Bitcoin mainly keeps a ledger of who owns which coins. Ethereum, launched in 2015, additionally runs programs that execute exactly the same way on every computer in the network. Think of it as a shared computer that nobody owns alone and nobody can switch off alone. The network's own currency is called ether, ETH for short.

Bitcoin mainly stores balances, Ethereum stores programs as well.

What a smart contract is

A smart contract is a program that lives on the blockchain and does exactly what its code says. The best-known picture is the vending machine: insert a coin, press a button, a can drops out, no seller needed. In the same way, whoever sends an amount to a contract gets something back by fixed rules, a token for example. Nobody has to approve, but nobody can step in either if the rules contain a mistake.

Code instead of a counterparty: what is written is what happens.

Full explanation

Why a contract made of code differs from one made of paper

A paper contract is a statement of intent. If one side does not keep to it, the other has to enforce its rights, in court if need be. There it gets interpreted: what was meant, what is reasonable, what was an honest slip. That interpretation is slow and expensive, but it catches mistakes.

A smart contract enforces itself. There is no interpretation, only execution. That is the advantage: nobody waits for a payment, nobody has to trust the other side, and the rules can be read by everyone before they join in.

It is also the drawback. If the code does something other than what was intended, the code wins. There is no goodwill gesture, no customer service and no judge to say that this was obviously not the plan. Whoever uses a contract therefore trusts not a person but the care of the people who wrote it.

What happened in 2016

In 2016 a smart contract called The DAO collected a great deal of ETH. It was meant to work like a jointly managed fund whose use the depositors would vote on. An attacker found a flaw in the code and used it to drain a large part of the funds without breaking a single rule of the network.

The community faced a question of principle. A majority chose a hard fork: a change to the rules that returned the drained funds. A minority rejected this because the chain was supposed to be immutable, and kept running the original chain under the name Ethereum Classic. Both have existed ever since.

The lesson still holds. First: a reviewed contract is not automatically a flawless one. Second: immutability is in the end an agreement between people, not a law of nature. And third: nobody should count on a rescue like that one, because it was a rare exception.

Two kinds of accounts

Ethereum has ordinary accounts controlled by a private key, in other words by a wallet. And it has contract accounts, which are backed by code. A contract never acts on its own: it stands still like a vending machine until a transaction calls it. Every action therefore starts with an account that has a private key.

A contract waits until someone calls it.

Gas: the fee meter

Every computing step on Ethereum costs a certain amount of gas. A simple transfer of ETH uses 21,000 gas, a complicated contract call considerably more. The fee is the gas used times the price per unit of gas. That price is usually stated in gwei, one billionth of an ETH. It works like a taxi meter: distance times price per kilometre.

Fee = gas used × price per gas.

Full explanation

Why computing has to cost money

On a shared computer every machine in the network has to re-run every program. If that were free, someone could start a program with an endless loop and keep the whole network busy. Gas prevents this: every step has a price, and whoever asks for computation pays for it.

That is why the sender of each transaction sets a limit on how much gas it may use at most. If the gas runs out, the action is aborted and everything it would have changed is rolled back. The gas used up to that point is still paid, because the computers did the work.

The price per gas is not fixed. It rises when many people want to send transactions at once and falls when things are quiet. That is why this module gives no current figure. Anyone who wants to know what a transfer costs right now can look it up on the fee pages.

Base fee and tip

Since a change in August 2021 the price per gas has two parts. The base fee is set by the protocol itself: it rises when blocks are full and falls when they are empty. On top comes a voluntary tip, the priority fee, which goes to whoever builds the block.

The base fee is not paid out but burned: it disappears from circulation. An example with made-up values: a transfer needs 21,000 gas, the base fee is 10 gwei and the tip 2 gwei. The sender pays 21,000 × 12 = 252,000 gwei, which is 0.000252 ETH. Of that, 210,000 gwei are burned.

Because ETH is constantly burned while new ETH is issued as a reward, the total supply can grow or shrink depending on conditions. Unlike Bitcoin there is no fixed cap. How the supply is developing at any moment depends on usage and is not a fixed number worth memorising.

Tokens on Ethereum

A contract can manage its own tokens. For fungible tokens, where every unit is worth the same like euro coins, there is the ERC-20 standard. For non-fungible tokens, so-called NFTs, where every piece is unique like a concert ticket with a seat number, there is ERC-721. A token is an entry in a contract, not ETH. The fee for sending it is still normally paid in ETH.

Sending tokens still requires ETH for gas.

No mining since 2022

Ethereum started out like Bitcoin with proof of work. In September 2022 the network switched to proof of stake. Since then blocks are proposed by validators who have deposited ETH as collateral, instead of by machines that burn electricity. Every twelve seconds there is a slot for a new block. The switch cut the network's electricity use by more than 99 percent.

The proof of stake module explains how validators work.

What smart contracts cannot do

A contract sees nothing outside the blockchain: no weather, no price on an exchange, no football score. Such data is brought in by oracles, and those have to be trusted in turn. The code is also public, so mistakes are visible to everyone, attackers included. And some contracts contain keys that let an operator change the rules later.

A contract is as trustworthy as its code and the data it receives.

Glossary

Smart contract
Program on the blockchain that runs exactly according to its code.
Gas
Unit of computing effort; every transaction pays for its gas.
Gwei
One billionth of an ETH; the usual unit for the price per gas.
Oracle
Service that brings data from outside onto the blockchain.
ERC-20
Standard for fungible tokens on Ethereum.
Hard fork
Rule change after which old and new software no longer agree with each other.

Further reading

This module comes with 18 explained questions. They live in the app, along with your progress and the credit for finishing.
The Coinovo appA reason to come back every dayTasks, shifts and the daily hunt, plus an account that shows what has added up.Daily tasksYour own accountCosts nothingStart now

More modules

What Bitcoin isMoney without a middlemanHow mining worksGuessing until it fitsHashrateHow much guessing goes onThe difficultyWhy the rhythm holdsThe halvingThe reward shrinksWallets and keysWhat you never hand overFeesYou pay for spaceMining poolsTogether instead of aloneSpotting fraudThe same tricks every timeTokenomics, taken apartBitcoin as the worked example, projects under testProof of stake and stakingCollateral instead of electricityStablecoinsStable as long as the backing holdsDeFi: financial services made of codeSwap, borrow, lend without a bankThe Lightning NetworkBitcoin instantly, with conditionsSpotting and stopping scamsCheck first, then signAI and cryptoA tool, not an oracleInvesting with a planRules instead of gut feelingRunning mining as a businessWhat a machine really costsSelf-custody in practiceFrom the first key to inheritanceTax and bookkeepingWhat the tax office wants to seeHow the network really worksNodes, mempool, forksRisk and position sizeHow not to lose everything