Mining Lab · Coinovo Academy · Ethereum and smart contracts
A shared computer with a fee meter
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.