Smart Contracts in Blockchain: What They Are and How They Work

On this page
What is a smart contract?
A smart contract is a computer program stored on a blockchain that runs automatically, exactly as written, whenever someone calls it with a transaction. It has its own address and can hold and send cryptocurrency, keep records and call other contracts. Because every node in the network runs the same code and must agree on the result, no single person, including the author, can tamper with how it executes once it is deployed.
Ethereum’s documentation borrows the metaphor Nick Szabo used in a 1996 essay, the vending machine: put in the right money and selection, and the machine reliably hands over the snack, with no shopkeeper involved. A smart contract does the same with digital assets. It is the core building block behind DeFi, stablecoins, NFTs and DAOs. Our smart contracts topic page collects related guides.
How do smart contracts work?
- Written in code. A developer writes the contract in a language such as Solidity or Vyper (Ethereum and compatible chains), Rust (Solana) or Move (Sui, Aptos).
- Compiled and deployed. The code is compiled to bytecode and sent to the network in a deployment transaction. From then on it lives at a fixed address, and anyone can read it.
- Called by transactions. A user or another contract sends a transaction to that address, calling one of its functions, such as “deposit”, “swap” or “vote”. The user signs with their wallet and pays a gas fee.
- Executed by every node. Validators run the function on a virtual machine, such as the Ethereum Virtual Machine (EVM). Execution is deterministic: the same input and state always produce the same output.
- State updated on-chain. If all the contract’s checks pass, balances and records change and the result is recorded in a block. If any check fails, the whole transaction reverts and nothing changes, although the gas spent is still lost.
A simple example: an on-chain swap
Say Alice wants to swap 1,000 USDC for ETH. On a decentralized exchange, she sends one transaction to the exchange’s contract. In a single step the contract:
- checks she has approved the USDC and that the pool holds enough ETH,
- calculates the price from its formula,
- takes her USDC and sends her the ETH,
- and reverts the whole thing if the price moved beyond her slippage limit.
There is no broker, no settlement delay and no counterparty who can walk away halfway through. Either everything happens or nothing does.
What smart contracts cannot do alone
The old textbook example of buying a house “by smart contract” shows the limits. A contract can move tokens it controls, but it cannot hand over a physical property, because the land registry is off-chain. It also cannot check a delivery or a court ruling. To use real-world data, such as asset prices, contracts rely on oracles: services that publish outside information on-chain. That reintroduces trust in whoever runs the oracle.
Types and uses of smart contracts
| Use | What the contract does | Examples |
|---|---|---|
| Tokens | Track balances and transfers (ERC-20 and similar) | USDC, DAI, governance tokens |
| Exchanges | Pool liquidity and price trades by formula | Uniswap, Curve |
| Lending | Accept collateral, issue loans, liquidate unsafe positions | Aave, Compound, Morpho |
| Stablecoins | Mint and redeem coins against collateral | Sky (formerly Maker), Liquity |
| NFTs | Prove ownership of unique tokens | ERC-721 collections |
| DAOs and multisigs | Hold a treasury and execute votes or co-signed payments | Governor contracts, Safe multisigs |
| Escrow and payments | Release funds when conditions are met | Streaming payments, vesting |
For a deeper breakdown, see the different types of smart contracts and which cryptocurrencies use smart contracts. DeFi contracts alone held about $71 billion of deposits on November 16, 2026, according to DefiLlama, down from a peak of nearly $178 billion in November 2021.
Benefits of smart contracts
- No intermediary needed. Code enforces the rules, so you don’t need to trust a counterparty or pay a middleman.
- Transparency. The code and every transaction are public, so anyone can verify what a contract does and holds.
- Speed and availability. Contracts settle in seconds to minutes, 24/7, worldwide.
- Permissionless. Anyone can deploy or use a contract without asking for approval.
- Composability. Contracts can call one another, so developers build new products on top of existing ones, like Lego bricks.
Limitations and risks
- Bugs are costly and public. Anyone can read the code, including attackers. In 2016 a flaw in “The DAO” contract let an attacker drain over 3.6 million ETH, according to ethereum.org. That led to the July 20, 2016 hard fork that moved the funds to a withdrawal contract, and to the split with Ethereum Classic. Exploits still happen every year; see common smart contract vulnerabilities.
- Transactions are irreversible. There is no bank to call if you send funds to the wrong address or sign a malicious approval. Our Q&A on why smart contract transactions are irreversible explains why.
- Immutability cuts both ways. Code can’t be patched in place. Many projects therefore use upgradeable proxies, which means an admin key or governance vote can change the logic, and that key becomes a point of trust.
- Oracle risk. A wrong or manipulated price feed can trigger unfair liquidations or let attackers borrow against inflated collateral.
- Cost and size limits. Every computation costs gas, and Ethereum mainnet caps deployed contract code at 24 KiB (24,576 bytes, set by EIP-170 in 2016), so complex logic gets split across contracts. The upcoming Glamsterdam upgrade lists EIP-7954 as scheduled for inclusion; it would raise the limit to 64 KiB (65,536 bytes). Glamsterdam activated on the Sepolia testnet on October 6, 2026, but its Hoodi testnet fork was postponed indefinitely in October 2026 and, as of mid-November 2026, it has no mainnet date, so the 24 KiB limit still applies on mainnet and Glamsterdam’s final scope could still change.
- Legal uncertainty. Code does not settle every dispute. Whether a smart contract forms a legally binding agreement depends on ordinary contract law; see are smart contracts legally binding?.
Audits by specialist firms reduce risk but don’t remove it, and some users buy cover through decentralized insurance protocols.
A short history
- 1994: Nick Szabo introduces the term “smart contract” for a computerized transaction protocol that executes the terms of a contract. His 1996 essay expands the idea, citing the vending machine as a primitive ancestor.
- 2009: Bitcoin’s scripting language allows simple conditions, such as multisignature spending, but is deliberately limited.
- July 30, 2015: Ethereum’s Frontier launch brings general-purpose, programmable smart contracts to a public blockchain.
- 2016: The DAO exploit shows the stakes of contract bugs and leads to the July 20 hard fork.
- 2020 onward: DeFi, NFTs and stablecoins turn smart contracts into infrastructure holding billions of dollars, across many chains and layer 2 networks.
How to use smart contracts safely
- Interact only through official front ends, and bookmark them.
- Read what your wallet asks you to sign, and limit token approvals.
- Prefer contracts with verified source code, public audits and a track record.
- Check who can upgrade or pause the contract.
- Start with small amounts.
If you want to write one, start with our guide to creating a smart contract, and see dApp vs smart contract to understand how contracts become full applications. This page is educational and not financial or legal advice.
Frequently asked questions
What is a smart contract in simple terms?
It is a piece of code that lives on a blockchain and automatically does what it was programmed to do, such as releasing funds when conditions are met. Ethereum's documentation compares it to a vending machine: the right input always produces the same output, with no shopkeeper needed.
Which blockchains support smart contracts?
Ethereum and the many networks compatible with its virtual machine (Arbitrum, Base, Optimism, BNB Chain, Avalanche C-Chain, Polygon), plus Solana, Cardano, Sui, Aptos, Tron and others. Bitcoin's scripting language supports only limited conditions.
Can a smart contract be changed or reversed?
The deployed code itself cannot be edited, and confirmed transactions generally cannot be reversed. Some contracts are deployed behind upgradeable proxies, which let an admin or governance vote swap in new logic.
Are smart contracts legally binding?
They can be. In advice published on 25 November 2021, the Law Commission of England and Wales concluded that the existing law of England and Wales can facilitate and support smart legal contracts. But code alone does not make a legal agreement; ordinary contract rules on offer, acceptance and intent still apply.
Who invented smart contracts?
Computer scientist and legal scholar Nick Szabo introduced the term in a 1994 essay, defining a smart contract as a computerized transaction protocol that executes the terms of a contract; a 1996 essay used the vending machine as an early example. Ethereum, launched on July 30, 2015, made general-purpose smart contracts practical on a public blockchain.
What is the difference between a smart contract and a dApp?
A smart contract is the on-chain code. A dApp is a full application, usually a website plus one or more smart contracts, that lets people use that code through their wallet.
Sources
- ethereum.org: Introduction to smart contracts
- ethereum.org: Ethereum Virtual Machine (EVM)
- ethereum.org: Oracles
- ethereum.org: The history of Ethereum (Frontier and the DAO fork)
- Nick Szabo: Smart Contracts (1994)
- Nick Szabo: Smart Contracts, Building Blocks for Digital Markets (1996)
- Law Commission of England and Wales: Smart contracts
- EIP-7773: Glamsterdam hardfork meta (includes EIP-7954, larger contract size limit)
- OpenZeppelin: Proxy upgrade pattern
- DefiLlama: DeFi total value locked
Educational content, not financial advice. DeFi carries risk, including total loss of funds.