What is a smart contract? It is a computer program stored on a blockchain that automatically carries out the terms of an agreement when pre-set conditions are met — no bank, lawyer or middleman required. Put money in, meet the conditions, and the code does the rest, exactly as written, every single time. The idea is older than Bitcoin itself: cryptographer Nick Szabo described it in 1994, a decade and a half before the first blockchain existed to run it on.
Today smart contracts are the machinery underneath almost everything in crypto beyond simple payments. They run decentralised exchanges, lending protocols, NFT marketplaces and the stablecoins that move billions of dollars a day. They are also unforgiving: a bug in a smart contract cannot be recalled like a faulty product. This guide explains how smart contracts work, where they are used, and what can go wrong.
In this article
- Key Takeaways
- What Is a Smart Contract?
- How Do Smart Contracts Work?
- A Short History: From Szabo to Ethereum
- Smart Contract Examples: Where They Actually Run
- Smart Contract Risks: When Code Goes Wrong
- Are Smart Contracts Legally Binding?
- Facts and Figures
- What to Watch Next
- Frequently Asked Questions
- Related Articles
Key Takeaways
- A smart contract is self-executing code on a blockchain that runs automatically when its conditions are met, with no intermediary.
- Nick Szabo coined the term in 1994 and used the vending machine as his analogy; Ethereum made it practical when it launched in 2015.
- Most smart contracts are written in Solidity and run on the Ethereum Virtual Machine (EVM); every operation costs gas, paid in ETH.
- Smart contracts power DeFi lending, decentralised exchanges, NFTs, DAOs and stablecoins — DeFi alone holds about $67 billion in value.
- Once deployed, a contract’s code is usually immutable, so bugs can be catastrophic: the 2016 DAO hack drained 3.6 million ETH.
- In England and Wales, the Law Commission concluded in 2021 that existing law can support legally binding smart contracts without new legislation.
What Is a Smart Contract?
A smart contract explained in one sentence: it is an agreement written as code, stored on a blockchain, that executes itself. Traditional contracts describe what should happen and rely on people — or courts — to make it happen. A smart contract skips that step. Its terms are “if this, then that” rules: if the buyer sends payment, release the digital asset; if a loan’s collateral falls below a threshold, sell it automatically. Once the conditions are satisfied, the outcome is not a matter of trust or enforcement. It is a matter of computation.
Szabo’s original definition still holds up well: “a computerized transaction protocol that executes the terms of a contract.” His aims were to satisfy common contractual conditions, minimise exceptions — both malicious and accidental — and minimise the need for trusted intermediaries. His favourite illustration was the humble vending machine. You insert coins, press a button, and the machine dispenses the snack. No cashier, no negotiation, no trust required beyond the machine itself. A smart contract is that vending machine, rebuilt in software, handling digital assets on a public ledger where anyone in the world can use it.
How Do Smart Contracts Work?
How do smart contracts work in practice? The lifecycle has four stages: writing, compiling, deploying and executing. A developer writes the contract in a programming language — most commonly Solidity for Ethereum and other EVM-compatible chains. The code is compiled into bytecode, a low-level form that the blockchain’s virtual machine can run. The developer then sends a special transaction that stores that bytecode on the blockchain. The contract receives its own permanent address, and from that moment it exists independently: it can hold funds, own tokens and interact with other contracts.
Execution begins when someone sends a transaction to the contract’s address. Every node on the network runs the same function call with the same inputs and must reach the same result; that is how the network agrees on the outcome without a central authority. Each operation costs gas, a unit that meters computation and storage. A simple transfer of ether costs around 21,000 gas, an ERC-20 token transfer roughly 65,000, and a complex DeFi swap 150,000 or more. Gas is paid in the chain’s native currency — ETH on Ethereum — and it serves two purposes: it compensates the network for the work, and it puts a hard cap on how much computation any single transaction can demand, which prevents infinite loops from freezing the chain.
One of the most important design choices is immutability. Once a contract is deployed, its code generally cannot be changed. This is a feature, not an oversight: users can inspect the code, verify it does what it claims, and trust that it will keep doing exactly that. But it also means mistakes are permanent, and workarounds such as proxy contracts — where a front-end contract points to logic that can be swapped out — reintroduce trust in whoever controls the upgrade.
There is also the question of information. A blockchain cannot see the outside world: a smart contract cannot by itself know the price of bitcoin or the result of a football match. That gap is filled by oracles — services that feed external data onto the chain. Chainlink is the dominant decentralised oracle network, supplying price feeds that DeFi protocols depend on. Oracles are powerful, but they are also a point of failure: if the data feed is wrong or manipulated, the contract executes faithfully on bad information.
A Short History: From Szabo to Ethereum
The smart contract story starts in the 1990s, long before anyone had heard of a blockchain. Nick Szabo, a computer scientist and legal scholar, published his ideas in 1994 and developed them through the decade. He saw that cryptography and digital protocols could automate the performance of agreements — escrow, payments, property transfers — and reduce the friction of doing business with strangers. The vision was sound. The infrastructure was not there: no widely trusted, tamper-proof computer existed that everyone could share, so the idea stayed theoretical.
Bitcoin, launched in 2009, proved that a decentralised ledger could work, but its scripting language was deliberately limited: it could handle payments and a few simple conditions, not general-purpose programs. The breakthrough came when Vitalik Buterin published the Ethereum whitepaper in 2013, proposing a blockchain with a built-in programming language — a “world computer” that could run many independent smart contracts at the same time. Ethereum launched in 2015, and with it came Solidity, the language proposed by co-founder Gavin Wood in August 2014 and developed by Christian Reitwiessner and colleagues, designed specifically for writing contracts for the Ethereum Virtual Machine.
The first great test came almost immediately. In April 2016, The DAO — a venture fund run entirely as a smart contract — raised around 12.7 million ETH, worth roughly $150 million, from more than 11,000 contributors, making it the largest crowdfunding event in history at the time. It held about 14% of all ether in circulation. On June 17, 2016, an attacker exploited a reentrancy bug in its withdrawal function — the contract sent funds before updating the sender’s balance, so the attacker could call it again and again inside a single transaction — and drained 3,641,694 ETH, worth about $60 million.
What followed was the most consequential argument in crypto history. The stolen ether sat in a child DAO behind a 28-day holding period, giving the community time to act. After weeks of fierce debate, the network executed a hard fork on July 20, 2016, at block 1,920,000, moving the funds to a recovery contract so investors could reclaim them. Around 89% of mining power followed the fork. A minority rejected the rollback on principle — immutability is supposed to be absolute — and kept running the original chain, which survives today as Ethereum Classic.
Smart Contract Examples: Where They Actually Run
The most familiar smart contract examples are in decentralised finance. On a lending protocol such as Aave, a smart contract holds your collateral, issues your loan, charges interest and liquidates your position if the collateral value falls too far — all automatically, 24 hours a day, with no loan officer involved. On a decentralised exchange such as Uniswap, contracts hold pools of tokens and price trades by formula, so anyone can swap assets without an order book or a counterparty. Stablecoins such as USDT and USDC are themselves smart contracts: token contracts that track balances, enforce transfers and, in the issuers’ case, allow freezing addresses under court order — as happened when Tether and Circle froze billions in USDT and USDC after the Binance hack.
Beyond DeFi, the same machinery runs NFTs. An NFT is a token governed by a contract — usually the ERC-721 standard — that records who owns a unique digital item and enforces the rules for transferring it, including royalty payments to the creator on resale. DAOs, or decentralised autonomous organisations, use contracts to run treasuries and votes: members hold governance tokens, propose spending, and the contract executes the outcome of a vote without anyone’s permission. Supply chains, insurance and gaming use them too — parametric crop insurance, for example, can pay a farmer automatically when a weather oracle reports rainfall below a threshold, with no claims adjuster involved.
The scale is now substantial. DeFi protocols hold around $67 billion in total value locked, according to our report on DeFi TVL, and every dollar of it sits in smart contracts. Tokenised real-world assets — shares, bonds, property funds represented as tokens — are the fastest-growing use case, with traditional finance firms issuing instruments on public chains. What unites all of these uses is the same property: the rules are public, the execution is automatic, and no single party can quietly change the deal. That is the promise. The risks come from the gap between the code as written and the code as intended.
Smart Contract Risks: When Code Goes Wrong
Smart contract risks start with the obvious: bugs are permanent and public. A flaw in a traditional app can be patched quietly overnight. A flaw in a deployed smart contract is visible to every attacker on earth, and fixing it may require migrating all users and funds to a new contract — if that is even possible. The DAO hack was the first lesson, but it was far from the last. Reentrancy, the bug class behind The DAO, was still claiming victims in 2025, when a reentrancy flaw in GMX v1 cost around $42 million.
The numbers tell a more nuanced story than the headlines suggest. In 2025, crypto lost about $3.4 billion to hacks, according to Chainalysis — the worst year on record. But the single biggest event, the $1.46 billion Bybit breach in February 2025, was a supply-chain attack on a wallet interface by North Korea’s Lazarus Group, not a smart contract bug at all. DeFi protocol losses — the part actually caused by smart contract failures — were around $680 million, according to Immunefi, far below the $2.62 billion peak of 2022. Smart contract vulnerabilities still account for most incidents by count, but infrastructure and operational failures drove about 76% of losses by value.
That does not mean code is safe. In May 2025, Cetus Protocol lost $223 million to an integer overflow in its pricing logic. In November 2025, Balancer V2 lost around $128 million to an exploit that accumulated tiny rounding errors across hundreds of batch swaps — a class of economic attack that standard audits often miss. And 2026 brought fresh damage: the Drift Protocol hack on April 1 drained roughly $285–295 million, and the Kelp exploit on April 18, which abused a bridge weakness to mint about $293 million of unbacked tokens, knocked billions off Aave’s total value locked within days as confidence drained from DeFi lending.
The industry’s defences have matured in response. Professional audits are now standard for serious protocols, bug bounties pay researchers to find flaws before attackers do, and formal verification — mathematically proving that code behaves as specified — is gaining ground. But audits are not guarantees: several of 2025’s victims had been audited. The honest summary is that ethereum smart contracts and their cousins on other chains are far more secure than they were in 2016, and still not secure enough to trust blindly. Prefer protocols with a long track record, multiple audits and a public bug bounty — and never put more into any single contract than you can afford to lose.
Are Smart Contracts Legally Binding?
The legal status of smart contracts is a question with a genuinely interesting answer, and it depends on where you are. In England and Wales, the position is now unusually clear. The UK Jurisdiction Taskforce concluded in its November 2019 legal statement that smart contracts are, in principle, capable of giving rise to binding legal obligations enforceable in accordance with their terms. The Law Commission went further in its advice to Government, published on November 25, 2021, concluding that the current legal framework in England and Wales “is clearly able to facilitate and support the use of smart legal contracts, without the need for statutory law reform.”
The Commission defined a smart legal contract as a legally binding contract in which some or all of the contractual obligations are defined in and/or performed automatically by a computer program. It identified three forms: a natural-language contract with automated performance by code; a hybrid contract mixing natural language and code; and a contract expressed solely in code. In most cases, whether a smart contract is binding turns on the same requirements as any traditional contract — agreement, consideration, certainty and an intention to create legal relations. Automated performance is not new: bank payments and online shopping have done it for years.
There are caveats. Interpreting a contract written wholly in code raises novel questions — a program may not always perform the way a reading of the code suggests, and identifying consideration can be harder when promises are defined in code. The Commission also flagged deeds and private international law as areas needing further work. And the position varies by jurisdiction: other countries have taken different approaches, from specific legislation to silence.
For practical purposes, the important distinction is between a smart contract as a piece of software and a smart legal contract as a binding agreement. Most DeFi protocols are the former: they execute code, and whether a court would treat any given interaction as a contract is largely untested. The DAO hack’s aftermath showed why this matters — the attacker argued, in an open letter, that the funds had been obtained “legally” under the rules of the contract as written. The community disagreed, and forked. Code may be law inside the machine, but outside it, the law still has the last word.
Facts and Figures
| Item | Detail (as of November 21, 2026) |
|---|---|
| Term coined | 1994, by Nick Szabo |
| Szabo’s definition | “A computerized transaction protocol that executes the terms of a contract” |
| Classic analogy | The vending machine |
| Ethereum whitepaper | 2013, by Vitalik Buterin |
| Ethereum mainnet launch | 2015 |
| Solidity proposed | August 2014, by Gavin Wood |
| Solidity latest version | 0.8.35 (April 2026) |
| Execution environment | Ethereum Virtual Machine (EVM) |
| Simple ETH transfer | ~21,000 gas |
| ERC-20 token transfer | ~65,000 gas |
| Complex DeFi swap | ~150,000+ gas |
| The DAO raised | ~12.7M ETH (~$150M), April–May 2016 |
| The DAO hack | 17 June 2016 — 3,641,694 ETH (~$60M) drained |
| The DAO hard fork | 20 July 2016, block 1,920,000 |
| Ethereum Classic | Minority chain that rejected the fork |
| DeFi total value locked | ~$67 billion (November 2026) |
| Crypto stolen in 2025 | ~$3.4B (Chainalysis); DeFi protocol losses ~$680M (Immunefi) |
| Largest 2025 hack | Bybit, $1.46B (Feb 2025, supply-chain attack, not a contract bug) |
| Largest 2025 contract exploit | Cetus Protocol, $223M (May 2025) |
| UK Law Commission advice | 25 November 2021 — existing law supports smart legal contracts |
| Leading oracle network | Chainlink |
What to Watch Next
First, watch the formal verification and AI-audit wave. As contracts hold more value, the industry is moving beyond human code review toward mathematical proofs of correctness and AI-assisted auditing — and toward simpler, standardised contract templates that are easier to verify. The protocols that adopt these tools first will have a real trust advantage.
Second, watch real-world assets and institutional adoption. Tokenised funds, bonds and shares are bringing regulated finance onto smart contract rails, and the legal questions are moving with them: how courts treat tokenised ownership, what happens when a contract and a prospectus disagree, and which jurisdiction governs a contract that exists everywhere and nowhere. The UK’s approach — existing law, no new statute — is being watched closely by other jurisdictions.
Third, watch Ethereum’s own evolution. The network’s next upgrade, Glamsterdam, is already delayed over smart contract risks, as our report on the Ethereum Glamsterdam upgrade explains — a reminder that the platform itself keeps changing under the contracts it hosts. Gas pricing changes, new virtual machine features and layer-2 scaling all affect what contracts can do and what they cost to run.
Frequently Asked Questions
Q: What is a smart contract in simple terms?
A smart contract is a computer program stored on a blockchain that automatically carries out an agreement when certain conditions are met. Think of a vending machine: insert the right money, press a button, and the snack is dispensed with no cashier involved. A smart contract does the same thing with digital assets — if the conditions are satisfied, the code executes the agreed outcome automatically, and no intermediary can stop or change it.
Q: How do smart contracts work?
A developer writes the contract in a language such as Solidity, compiles it into bytecode, and deploys it to a blockchain via a transaction. The contract gets its own permanent address and can hold funds and tokens. When someone sends it a transaction, every node on the network runs the same code and agrees on the result. Each operation costs gas, paid in the chain’s native currency, which pays for the computation and prevents abuse.
Q: What is a smart contract used for?
Smart contracts run decentralised finance (lending, trading, stablecoins), NFTs, DAOs, tokenised assets, insurance and gaming. Lending protocols use them to issue loans and liquidate collateral automatically; decentralised exchanges use them to price and settle trades; NFT contracts record ownership and pay creator royalties. Any agreement that can be expressed as “if this, then that” is a candidate.
Q: Are smart contracts safe?
They are safer than they were, but not risk-free. DeFi protocol losses from smart contract exploits were around $680 million in 2025, far below the $2.62 billion peak of 2022, and audits, bug bounties and formal verification have all improved. But bugs still happen — Cetus lost $223 million in May 2025 and Balancer around $128 million in November 2025 — and deployed code is usually immutable, so mistakes cannot simply be patched. Use established, audited protocols and never risk more than you can afford to lose.
Q: Are smart contracts legally binding?
They can be. In England and Wales, the Law Commission concluded in November 2021 that the existing legal framework can support legally binding smart contracts without new legislation, provided they meet the usual requirements of a contract: agreement, consideration, certainty and an intention to create legal relations. The position varies by jurisdiction, and most DeFi interactions have not been tested in court.
Q: What is the difference between a smart contract and a traditional contract?
A traditional contract is written in natural language and relies on people or courts to enforce it. A smart contract is written in code and enforces itself: once deployed on a blockchain, it executes automatically when its conditions are met, with no intermediary. The trade-off is flexibility — a traditional contract can be renegotiated or interpreted by a judge, while a smart contract does exactly what its code says, including when the code contains a bug.
Related Articles
- What Is Ethereum? ETH, Smart Contracts and DeFi Explained
- What Is DeFi? Decentralized Finance Explained
- How Does Blockchain Work? A Plain-English Guide
- Ethereum Glamsterdam Upgrade Could Slip to May 2027 Over Smart Contract Risks
- DeFi TVL Falls to $67 Billion as Ethereum, Base and Solana Shed Billions in a Week
Disclaimer: This article is for information purposes only and is not financial advice. Cryptocurrency prices are volatile and can move sharply in either direction. Do your own research before making any investment decision. All prices and figures are as of November 21, 2026.

Leave a Reply