Level 3 · How it worksThe village#217

Smart contracts explained: a rule in the notebook that runs itself, mistakes included

A smart contract is a program stored on a blockchain that runs exactly as written whenever someone sends it a transaction. Nobody can quietly change it, it can't see the outside world, and it carries out its mistakes as faithfully as its good ideas.

One page of the village notebook holds no names and no balances. It holds a rule: "Whoever leaves ether here gets the same amount written next to their name. Whoever hands that amount back gets the ether returned."

Nobody guards the page. When Rosa leaves 1 ether, every house reads the rule on its own copy, does what it says, and writes the same result. No clerk, no opening hours, no "computer says no" unless the rule says no.

That is a smart contract: a rule written into the notebook that runs itself. It can't be quietly changed, it can't see outside the village, and it does exactly what is written, including the mistakes.

What it is

ethereum.org's definition is short: "A 'smart contract' is simply a program that runs on the Ethereum blockchain" (ethereum.org). It sits in its own account with its own balance. Unlike your account, it has no private key: it's "controlled by code" (ethereum.org).

The idea is older than Ethereum. In 1997 the computer scientist Nick Szabo called the vending machine "the primitive ancestor of smart contracts" and wrote: "The vending machine is a contract with bearer: anybody with coins can participate in an exchange with the vendor" (Szabo, First Monday, 1997). Coins in, product out, no shop assistant.

How it works

Take a busy contract that has run since 2017, WETH9 (Wrapped Ether), at address 0xC02a...6Cc2. Wrapped tokens get their own article later; here it simply shows what a contract is.

  1. It was written once. The contract was created on 12 December 2017 at 11:17:35 UTC, in block 4,719,568 (Etherscan). Its source code is published and verified on Etherscan: the code the houses run matches the code anyone can read (Etherscan).
  2. It has a short menu. It has eleven named functions: name, symbol, decimals, totalSupply, balanceOf, allowance, deposit, withdraw, transfer, transferFrom and approve. Plain ether sent to it is treated as a deposit. There is no function for an owner, an admin or an upgrade.
  3. Rosa deposits. She sends 1 ETH to the deposit function. The rule adds 1 to her row in the contract's own list and logs a Deposit event. Rosa's account shows 1 ETH less; the contract holds 1 ETH more.
  4. Rosa withdraws. She calls withdraw with 1. The rule checks her row holds at least 1, subtracts it, and sends 1 ETH back to her account.
  5. The dated figure. On 19 November 2026 Etherscan showed the contract holding 2,101,165.708582848499453385 ETH, a little over 2.1 million, all of it placed there by people running the same two steps. Nobody at the contract decided anything.

Now the mistakes. The same Etherscan page listed more than 288 other kinds of token sitting at the contract's address on that day. People sent them there. The contract has no function that moves any token except its own, so they stay. The rule does what it says, not what the sender meant.

Why it matters

  • No middleman, no off switch. ethereum.org: "Smart contracts cannot be deleted by default, and interactions with them are irreversible." That protects you from a clerk changing the terms. It also means nobody can undo your mistake.
  • Anyone can write one. "Anyone can write a smart contract and deploy it to the network." The good, the careless and the stranger at the gate all use the same notebook.
  • Contracts build on contracts. ethereum.org calls them "open APIs": one contract can call another. A bug in one can spread to everything built on it.

Where people get it wrong

  • "A smart contract is a legal contract." It's a program. It may carry out a deal, but a court did not write it and won't necessarily read it.
  • "It knows the price of ether." It can't look outside. ethereum.org: "Smart contracts alone cannot get information about 'real-world' events". Someone has to write the outside world into the notebook, which "Oracles explained" covers.
  • "Can't be changed means safe." Many contracts are built to be upgraded by an admin key. Ben's dream is a rule he can rewrite after you've paid. On WETH9 he's out of luck; on others, check who holds that key.
  • "It's audited, so it does what I think." It does what its code says. An audit is someone else reading that code, not a promise.

Read the menu before you sign

Before your wallet calls any contract, look at what it will do: which function, which amount, which address. If the wallet shows a request to "approve" a token you didn't plan to spend, stop. That permission has its own article, and a lot of the stranger's income.

A contract is the most honest clerk in the village. It will do exactly what you ask, and it never says "are you sure?".

Frequently asked questions

What is a smart contract in simple terms?

A smart contract is a program stored on a blockchain such as Ethereum that runs exactly as written whenever someone sends it a transaction. Every node runs it on its own copy and gets the same result, so no single party has to be trusted to carry it out.

Who invented the idea of smart contracts?

The computer scientist Nick Szabo wrote about the idea before blockchains existed. In a 1997 article in First Monday he called the vending machine the primitive ancestor of smart contracts. Ethereum, launched in 2015, made it practical to run general programs of this kind on a blockchain.

Can a smart contract be changed after it is deployed?

The code at a contract's address can't be edited, and ethereum.org notes that contracts cannot be deleted by default. But some contracts are designed with an upgrade route or admin key that lets someone point them at new code, so it is worth checking who controls such keys.

Can a smart contract get information from the internet?

No. A contract can only read what is already on the blockchain. Outside data such as prices has to be written on chain by a service called an oracle.

What happens if I send tokens to a contract by mistake?

It depends on the contract's code. If the contract has no function to move those tokens, they stay there for good. Nobody, including the contract's creator, can reach in and send them back.

Sources

  1. ethereum.org, Introduction to smart contracts
  2. Nick Szabo, Formalizing and Securing Relationships on Public Networks, First Monday, vol. 2, no. 9 (1 September 1997)
  3. ethereum.org, Ethereum accounts
  4. Etherscan, WETH9 contract, verified source code and functions (read on 19 November 2026)
  5. Etherscan, WETH9 contract creation transaction, block 4,719,568 (12 December 2017)

Read next.