What is a smart contract, and what can go wrong with one?
A smart contract is a program that lives on a blockchain and runs exactly as written. That makes it powerful, and it is also why a single bug can be so costly.

The short answer
A smart contract is a program stored on a blockchain that runs automatically when someone sends it a transaction. Every node executes the same code, so no single party controls the outcome. Once deployed it is hard to alter, so bugs can be costly and losses are usually irreversible.
Key takeaways
- A smart contract is software deployed on a blockchain and executed by the computers that run that blockchain.
- On Ethereum, a contract is an account with its own address and balance, controlled by its code rather than by a private key.
- Every operation costs gas, a fee that pays for computation and stops programs from running forever.
- Contracts cannot fetch outside data on their own and, by default, cannot be deleted, so interactions are final.
- Coding mistakes have caused large losses, The DAO in 2016 being the best-known case, and audits reduce but do not remove that risk.
What is a smart contract, in plain terms?
NIST defines smart contracts simply as software deployed on a blockchain and executed by the computers running that blockchain1. Ethereum's documentation adds detail: a smart contract is a collection of code (its functions) and data (its state) that sits at a specific address on the chain2.
The classic comparison, which ethereum.org credits to Nick Szabo, is a vending machine2. The idea itself predates blockchains: a 2018 CFTC primer quotes a 1996 essay in which Szabo, a computer scientist, described a smart contract as "a set of promises, specified in digital form"9. Put in the right coins and press the right button, and the machine hands over a snack. No shop assistant decides whether you deserve it; the rules are built into the machine. A smart contract works the same way: given the right inputs, it produces a predetermined output.
Despite the name, a smart contract is not necessarily a contract in the legal sense. It is a program. It may carry out the terms of an agreement, but the code itself only does what it was written to do, including anything its authors did not intend.
Figure · Paper contract versus smart contract
Paper contract
- Written in human language
- Enforced by courts and people
- Can be amended by agreement
Smart contract
- Written in code
- Enforced by every node running it
- Hard to change once deployed
How does a smart contract run on a blockchain?
On Ethereum there are two kinds of account. An externally owned account is controlled by whoever holds its private key. A contract account is controlled by code, has no private key and only acts in response to a transaction it receives3. Contracts can hold a balance just like a person's account2.
The life of a smart contract
- 1
Write
A developer writes the program, usually in a language such as Solidity or Vyper2.
- 2
- 3
Call
A user sends a transaction to the contract's address, asking it to run one of its functions.
- 4
Execute and record
The computers running the network execute the code1, check that they reach the same result and record it in the next block.
Each step of computation costs gas, the unit Ethereum uses to measure computational effort4. Charging for every operation, and making each transaction set a limit on how much it can use, protects the network from spam and endless loops4. The fee is the gas used multiplied by a base fee, which is burned, plus an optional priority fee paid as a tip4.
Worked example
Working out a gas fee (illustrative numbers)
Suppose a contract call uses 50,000 gas, the base fee is 10 gwei and you add a 2 gwei tip. The fee is 50,000 × (10 + 2) = 600,000 gwei. Since one gwei is one-billionth of an ETH4, that is 0.0006 ETH. Real fees change with network demand.
If the call runs out of gas halfway, its changes are undone, but the gas already used is still charged4.
What are smart contracts used for?
Because contracts on Ethereum are public, other programs can call them like open building blocks, a property developers call composability2. Standards make this easier. The ERC-20 token standard, for example, defines a common set of functions, including transfer, balanceOf and approve, so that any compliant token can be used by wallets and decentralised exchanges without custom work7.
Common jobs done by smart contracts
| Use | What the contract does | Learn more |
|---|---|---|
| Tokens | Keeps a ledger of who owns how many units and moves them on request7 | Stablecoins |
| Exchanges | Swaps one token for another under fixed rules, without an order desk | DeFi explained |
| Lending | Holds collateral and releases it when a loan is repaid | DeFi explained |
| Tokenised assets | Represents claims on real-world assets as tokens | Tokenisation |
What can't smart contracts do?
Smart contracts have hard limits that beginners often miss. Ethereum's documentation lists several2:
- No outside data on their own. A contract cannot look up a price, a sports score or the weather. It relies on services called oracles to bring that data on-chain2.
- Size limits. A single contract on Ethereum can be at most 24 KB2.
- No undo button. Contracts cannot be deleted by default, and interactions with them are irreversible2.
- No judgement. The code cannot tell a mistake from an intention. If the rules allow something harmful, it will happen.
Some developers build in upgrade mechanisms or emergency stops to fix problems later, and ethereum.org lists these among recommended practices5. The trade-off is that whoever controls the upgrade can also change the rules, so users must trust that party.
What happened in The DAO hack, and why does it still matter?
The DAO was described by the U.S. Securities and Exchange Commission as a "virtual" organisation embodied in computer code and run on a blockchain6. Between 30 April and 28 May 2016 it sold about 1.15 billion DAO tokens in exchange for roughly 12 million ETH6.
On 17 June 2016, an unknown attacker began rapidly draining the contract, moving about 3.6 million ETH, a third of everything raised, to an address they controlled6. The code had done exactly what it allowed. The Ethereum community responded with a hard fork, a rule change that took effect on 20 July 2016 and moved the funds to a recovery address68. In a July 2017 report, the SEC concluded that DAO tokens were securities6.
Figure · The DAO, from sale to SEC report
- Apr 2016Token sale opens
- May 2016Sale closes, about 12m ETH raised
- Jun 2016Attacker diverts about 3.6m ETH
- Jul 2016Hard fork moves funds to recovery
- Jul 2017SEC: DAO tokens were securities
The DAO was not the last case. ethereum.org estimates that value stolen or lost through smart contract bugs is easily over $1 billion, citing among others a Parity multi-signature wallet attack and a separate Parity bug that left funds locked for good5. It also warns that audits will not catch every bug5.
What mistakes do beginners make with smart contracts?
Common beginner mistakes
Equating "audited" with "safe"
An audit is an extra review, not a guarantee; ethereum.org says audits will not catch every bug5.
Approving unlimited token spending
The ERC-20
approvefunction lets another address spend your tokens7. Granting a large allowance to a contract you do not understand exposes everything it covers.Assuming someone can reverse a mistake
Interactions with contracts are irreversible by default2. The DAO's hard fork was a rare, community-wide exception, not a service you can call on.
Ignoring who controls upgrades
If a contract can be upgraded, the people holding the upgrade keys can change how it works, including how it treats your funds.
Risk warning
Code risk is money risk
Sending funds to a smart contract means trusting its code and anyone who can change it. Bugs, exploits and design flaws have led to permanent losses. Use only amounts you can afford to lose and read our risk disclosure first.
Frequently asked questions
Are smart contracts legally binding?
The code is a program, not a legal document. Whether a particular arrangement is enforceable in court depends on the law where the parties are and on what they agreed outside the code.
Can a smart contract be changed after it is deployed?
Who can create a smart contract?
On Ethereum, anyone who can write the code and pay the gas fee can deploy one, with no permission needed2.
Why do smart contracts need gas?
Gas pays for the computation every node must perform and caps how much work a transaction can demand, which prevents spam and infinite loops4.
What language are smart contracts written in?
On Ethereum the most common languages are Solidity and Vyper2. Other blockchains use their own languages and virtual machines.
The bottom line
A smart contract is a program on a blockchain that runs the same way for everyone and cannot easily be stopped or edited. That predictability is useful for tokens, trading and lending, but it means mistakes are final too. Before trusting a contract with money, ask what it can do, who can change it and what happens if it is wrong.
Sources
- NIST IR 8202: Blockchain Technology Overview — National Institute of Standards and Technology, U.S. Department of Commerce, 2018 Primary source
- Introduction to smart contracts — ethereum.org developer documentation Primary source
- Ethereum accounts — ethereum.org developer documentation Primary source
- Gas and fees — ethereum.org developer documentation Primary source
- Smart contract security — ethereum.org developer documentation Primary source
- Report of Investigation Pursuant to Section 21(a) of the Securities Exchange Act of 1934: The DAO (Release No. 81207) — U.S. Securities and Exchange Commission, 2017 Primary source
- EIP-20: Token Standard — Ethereum Improvement Proposals (eips.ethereum.org), 2015 Primary source
- The history of Ethereum (network upgrades) — ethereum.org Primary source
- A Primer on Smart Contracts — LabCFTC, U.S. Commodity Futures Trading Commission, 2018 Primary source
How we checked this page: every figure above links to the numbered source it came from. Spotted an error? Tell the desk — see our editorial policy.
Read next
Tech · ExplainerHow does a blockchain work, and why is it so hard to change?A blockchain is a shared record book that thousands of computers keep in sync without a boss. Here is how the pieces fit together, from a single transaction to a chain of blocks.
Tech · ExplainerWhat is DeFi, and how does decentralised finance actually work?Decentralised finance rebuilds lending, trading and saving out of smart contracts on public blockchains. The plumbing is new; many of the risks are old ones in new clothes.
Tech · ExplainerWhat are token standards like ERC-20 and ERC-721, and why do they matter?Many different tokens can sit in the same wallet and trade on the same apps because they follow a handful of shared rulebooks. Here is what those rulebooks say.
Tech · ExplainerWhat is a blockchain oracle, and why do smart contracts need one?A smart contract can only see what is already on its blockchain. Oracles are the bridge to everything else, and they are often the weakest link in the chain.Assets · ProfileWhat is Ethereum, and what is ether actually for?Ethereum is a shared computer as much as a payment network. This profile explains how it runs, how ether is created and destroyed, and where things have gone wrong.
Policy · ExplainerWhat is the Howey test, and how does it decide if a crypto token is a security?A 1946 Supreme Court case about land and service contracts still decides whether many crypto tokens are securities in the United States. Here is how the test works and how the SEC used it in its 2026 crypto interpretation.