Code stored on a blockchain that executes automatically when its conditions are met — no intermediary required, no possibility of censorship.
A smart contract is a program deployed to a blockchain. Once deployed, its code is immutable and self-executing: anyone can call its functions, and the outcome is determined entirely by the code — not by a company, court, or intermediary. Nick Szabo coined the term in 1994, but it took until Ethereum (2015) to make general-purpose smart contracts practical.
Think of a vending machine: you insert coins, select an item, and it dispenses automatically — no cashier needed. A smart contract is a programmable vending machine that can hold funds, check conditions, and release assets to any party on Earth, 24/7, without requiring trust in any operator.
Ethereum's Ethereum Virtual Machine (EVM) is a sandboxed execution environment. Every Ethereum node runs the EVM identically, so a contract always produces the same output from the same input — which is how thousands of nodes can verify execution without trusting each other. Computation is metered with gas: each opcode has a gas cost, and callers pre-pay, preventing infinite loops from halting the network.
Gas serves two purposes: (1) it compensates validators for computation, and (2) it prevents denial-of-service by making infinite or excessively expensive operations financially costly to the caller. If a transaction runs out of gas mid-execution, all state changes are reverted but the gas is consumed — punishment for submitting a poorly written transaction.
A smart contract goes through three phases. Deployment: compiled bytecode is sent as a transaction with no recipient — the EVM assigns it an address and stores it on-chain. Execution: external accounts or other contracts call its functions; state changes are committed atomically. Selfdestruct: (optional) the contract can mark itself for deletion, returning any remaining ETH to a specified address.
Smart contract security is a discipline of its own — billions of dollars have been lost to contract vulnerabilities. The most important patterns to know: checks-effects-interactions (update state before calling external contracts to prevent re-entrancy), pull over push (let users withdraw funds rather than pushing to them), and access control (restrict sensitive functions to authorised callers using require(msg.sender == owner)).
locked boolean that prevents a function from being called recursively. OpenZeppelin's ReentrancyGuard is the standard implementation.Say the answer out loud before revealing — recalling is what makes it stick.
What is a smart contract?
What is gas in Ethereum?
What is a re-entrancy attack?
Why can't smart contracts read real-world data directly?