Every time you swap one token for another on a decentralized exchange, borrow against your crypto, or mint an NFT, a piece of code runs your deal automatically — no bank, broker, or lawyer in the middle. That code is a smart contract, and today more than $200 billion in assets sits locked inside these programs across the crypto market.
So what is a smart contract, really? This plain-English guide explains how smart contracts work, walks through examples you have probably already used, shows what they cost to run, and covers the one feature beginners consistently underestimate: the code is final. If you are new to this world, a beginner crypto course that starts from the fundamentals will make the rest of this far easier to follow.
- A smart contract is self-executing code on a blockchain that runs automatically when its conditions are met.
- It removes the middleman: the network enforces the deal, not a bank, escrow agent, or court.
- Running one costs "gas" — from ~21,000 units for a simple transfer to 200,000–500,000 for complex DeFi.
- The catch: once deployed, the code is final. Bugs are not disputes you can appeal — they are exploits.
- Smart-contract flaws have cost users billions; in 2026 alone DeFi lost over $840 million to exploits.
What is a smart contract, in plain terms?
A smart contract is a self-executing program stored on a blockchain that automatically carries out an agreement when predefined conditions are met. There is no company running it and no one to phone. The rules are written in code, the code lives on the network, and it does exactly what it says — every time, for everyone, without asking permission.
The idea is older than crypto. Computer scientist Nick Szabo coined the term "smart contract" in 1994, defining it as "a computerized transaction protocol that executes the terms of a contract." His favorite analogy was the humble vending machine: put in the right coins, press the button, and the machine hands over the item and your change with no cashier involved. The logic is baked into the hardware.
What Szabo could not build in the 1990s was a neutral, tamper-resistant place to run that logic. That arrived with Ethereum in 2015, the first blockchain designed to run arbitrary programs. Contracts are usually written in Solidity, a language proposed by Ethereum co-founder Gavin Wood in 2014 and first released that same year Ethereum went live. Since then, smart contracts have become the engine under almost everything in crypto beyond simply sending coins.
How does a smart contract actually work?
A smart contract works in four stages: a developer writes and deploys the code to the blockchain, users interact with it, the network checks the conditions, and the contract settles the outcome — all without a trusted middleman. Here is the sequence in practice.
- Deploy. The finished code is published to the blockchain at its own address. From that moment it is public, permanent, and readable by anyone.
- Trigger. A user sends a transaction to that address — for example, "swap 1 ETH for USDC" — along with the fee to run it.
- Execute. Every full node on the network runs the contract's code in its own copy of the Ethereum Virtual Machine (EVM), checking that the conditions hold.
- Settle or revert. If the logic succeeds, the new balances are written to the chain permanently. If it fails — out of funds, a failed check, a safety guard — the whole thing rolls back as if it never happened.
That last point matters more than beginners expect. Because thousands of independent computers run the same code and must agree on the result, no single party can quietly change the outcome. The trade-off is that computation is not free — someone has to pay for all that work.
What does running a smart contract cost? Gas, explained
Every operation the EVM performs has a fixed price measured in gas units. A plain transfer of ETH costs about 21,000 gas. A complex DeFi interaction — a multi-step swap, a leveraged loan — can cost anywhere from 200,000 to 500,000 gas units. You then pay a price per unit, quoted in gwei (1 gwei = 0.000000001 ETH), which rises and falls with how busy the network is.
What different smart-contract actions cost, in gas units
Source: Ethereum protocol gas costs via Blockchain Council, 2026, and web3.university, 2026. Gas units, not dollars — the dollar cost also depends on the live gwei price.
What this means for you: the fee is not random, it is a measure of how much computing your action demands. A single reason DeFi can get expensive is that one "click" may quietly call several contracts in sequence. If you want the full breakdown of how the final bill is built, see our explainer on how Ethereum gas fees are calculated, including the base-fee-plus-tip split introduced by the EIP-1559 upgrade in August 2021.
What can you actually do with smart contracts?
You have almost certainly used a smart contract without calling it that. They are the plumbing beneath most of crypto. The clearest smart contract examples a beginner meets are:
- Token swaps. Decentralized exchanges like Uniswap are just smart contracts that hold pools of two tokens and price trades between them automatically.
- Lending and borrowing. Deposit collateral into a lending contract and it lets you borrow against it, charging interest and liquidating you by code if your collateral falls too far.
- Stablecoins. Many stablecoins are issued and redeemed through contracts that manage the supply and the reserves backing each coin.
- NFTs. An NFT is a contract that tracks who owns each unique token and can pay the creator a royalty on every resale.
- DAOs. Decentralized organizations use contracts to hold a shared treasury and execute whatever the members vote to approve.
Stack all of this together and you get an entire financial system running on code. That is what people mean by DeFi, and it is why so much money now sits inside these programs — roughly $200 billion in total value locked across all chains as of May 2026. If the category is new to you, start with how decentralized finance is built on smart contracts, then come back here.
Smart contract vs a traditional contract: what really changes
A paper contract is a promise backed by the legal system. A smart contract is a promise backed by code and thousands of computers. The difference is not cosmetic — it changes who enforces the deal, how fast it settles, and, crucially, whether you can ever undo it.
| Factor | Traditional contract | Smart contract |
|---|---|---|
| Who enforces it | Courts and intermediaries | Code, run by every node on the network |
| Execution | Manual, often days or weeks | Automatic, in seconds |
| Middleman | Bank, lawyer, or escrow agent | None — the contract is the agent |
| Cost | Legal and processing fees | A gas fee to run the code |
| Availability | Business hours | 24/7, worldwide |
| Reversible | Yes — disputes, appeals, chargebacks | No — final once executed |
Read that bottom row twice. Removing the middleman is the whole promise of smart contracts — and removing the middleman is also what removes your safety net. There is no manager to reverse a mistaken transaction and no court that can force the code to behave differently than it was written.
The catch: on a blockchain, code is final
Here is the hard part. Because a smart contract executes exactly as written and cannot be reversed, a bug in the code is not a paperwork error — it is a door left open, and someone will walk through it. The most famous example set the tone for the entire industry.
In June 2016, an attacker exploited a "reentrancy" flaw in a project called The DAO and drained roughly 3.6 million ETH, worth about $60 million at the time, out of a fund that had raised around $150 million. The code did nothing "wrong" — it did precisely what it was written to do. The fallout was so severe that Ethereum hard-forked to reverse the theft, permanently splitting the network into Ethereum and Ethereum Classic.
This is not ancient history. Smart-contract exploits remain the defining risk of the space, and the numbers are getting larger, not smaller.
Source: TVL via KuCoin, 2026; 2026 exploit total via altfins and CCN, 2026; DAO figures via Gemini Cryptopedia and IEEE Spectrum, 2016.
Notice where the losses come from. Most exploits are not someone "hacking the blockchain" — that is extremely hard. They are logic flaws, oracle manipulation, or unchecked permissions in a single contract's code. The chain works perfectly; the program on top of it had a mistake. That distinction is why the infrastructure layer and the application layer carry very different risks, a theme we cover in the trade-offs between Layer 1 and Layer 2 blockchains.
Are smart contracts safe to use?
Smart contracts are as safe as the code behind them and the habits of the person signing the transaction. The technology is not the weak point — unaudited code and careless approvals are. A few practical rules cut most of a beginner's risk:
- Prefer audited, battle-tested protocols. A contract that has held billions for years without incident is a very different bet than one launched last week with an anonymous team.
- Understand token approvals. Many hacks succeed because users grant a contract unlimited permission to spend their tokens and never revoke it. Approve only what you need.
- Read what you are signing. Your wallet tells you what a transaction will do. If a "free mint" asks for spending access to your whole balance, stop.
- Assume finality. There is no undo button. Send a small test amount first when you interact with something new.
- Do not confuse popularity with safety. A trending protocol can still hold a fatal bug; the DAO was the most-funded project of its year.
None of this requires you to become a Solidity developer. It requires the same discipline good traders bring to any market: understand the instrument before you commit capital to it.
Frequently asked questions
Crypto assets are highly volatile and smart-contract interactions carry a real risk of total loss; regulation varies by country. This article is educational content, not investment advice.