Smart Contract

A program stored on a blockchain that runs automatically, exactly as written, when it is called.

What is a Smart Contract?

A smart contract is a computer program stored on a blockchain. It runs when a transaction calls it, and every node on the network executes the same code and reaches the same result. A smart contract can hold funds and move them according to its rules, with no intermediary needed to carry out the agreement.

How it works

A developer writes the contract, on Ethereum usually in a language called Solidity, and deploys it with a transaction. The contract receives its own address. Users and other contracts interact with it by sending transactions to that address, specifying which function to run. The network executes the code, updates the contract's stored data and records the outcome in a block. Each step of computation costs gas, paid by the caller.

Once deployed, a contract's code generally cannot be changed, unless it was deliberately built to be upgradeable.

The term was coined in the 1990s by the computer scientist Nick Szabo, who compared the idea to a vending machine: insert the right input and the machine delivers the product automatically. Ethereum, launched in 2015, was the first major blockchain designed around general-purpose smart contracts.

Example

A token is a smart contract that records balances and lets holders transfer them. A decentralised exchange is a set of contracts that hold pools of tokens and swap one for another by formula. A lending protocol releases a loan when collateral is deposited and sells the collateral if its value falls too far.

Why it matters

Smart contracts make blockchains programmable. They are the foundation of tokens, DeFi, NFTs, DAOs and decentralised applications in general.

Risks and misunderstandings

Related terms