ArEn

Lesson 9 of 135 min read

Web3 and digital applications · Beginner

Smart contracts: code that keeps a promise

A smart contract is a small program stored on a blockchain that runs exactly as written whenever someone uses it. Nobody can pause it, change it on a whim, or refuse to pay out if its conditions are met. It is not smart, and it is not a legal contract: it is a promise written in code.

The vending machine idea

A vending machine is the classic picture. Put in the right amount, press a button, and the drink drops out. No shopkeeper decides whether you deserve it. A smart contract works the same way: if these conditions are met, then do this, automatically, for anyone.

How it runs

  • Someone writes the program and puts it on a blockchain such as Ethereum. From then on it has its own address, like a wallet.
  • Anyone can send it a transaction to use it, paying a small fee to the network.
  • Every computer in the network runs the same code and agrees on the result, so the outcome cannot be quietly changed.

Example

A ticket contract for a concert holds 500 digital tickets at USD 40 each. Omar sends USD 40 in a stablecoin to the contract; within seconds the contract gives him ticket number 213 and the money goes to the organiser. When Omar sells his ticket to a friend, the contract checks it is genuine, moves it, and can even pay the organiser a small share, all without a ticket office.

What they are used for

  • Exchanging one token for another without a company in the middle.
  • Lending and borrowing, with the loan's rules enforced by code.
  • Digital items and tickets whose ownership anyone can check.
  • Stablecoins, which are themselves smart contracts that track who holds how many.

The catch: code can be wrong

A smart contract does what it says, not what its makers meant. If the code has a mistake, attackers can use it, and there is usually no bank to reverse the damage. Some contracts can be upgraded by their team, which fixes bugs but also means you are trusting that team. Before using one with real money, check how long it has run, whether independent auditors reviewed it, and how much others trust it with.

In short

  • A smart contract is a program on a blockchain that runs exactly as written.
  • If these conditions are met, it acts, for anyone, without a middleman.
  • A bug can cost real money and rarely can be undone, so trust tested contracts only.

Quick quiz

  1. What is a smart contract?

  2. Which everyday machine works like a smart contract?

  3. A smart contract has a bug and is drained. Who usually reverses it?