A smart contract is a small program that lives on a blockchain and runs on its own. You send it an instruction, its conditions are met, and it does what the code says. No bank signs off on the transfer. No lawyer files anything. The code holds the money, and the code moves it.
That is the whole idea. It is also where the trouble starts. This guide walks through what a smart contract really is, what happens the moment one goes live, what people build with them, and why billions of dollars have leaked out of them over the years.
A program that holds its own money
Picture a vending machine. You drop in a coin, press a button, and a can falls out. Nobody decides whether you deserve the drink. The machine follows one rule: correct payment in, product out.
A smart contract works along the same lines, except it lives on a network like Ethereum and it can hold real value. Its rules are written in code and stored on the chain, where thousands of computers each keep a copy. When someone calls the contract and the conditions check out, all of those computers run the identical code and agree on the outcome. The result is not a pledge to pay later. It has already happened, and it is recorded for anyone to see.
The term goes back to the computer scientist Nick Szabo, who described the concept in the 1990s, long before any of this ran on a live blockchain. His favorite example was that same vending machine, a device that enforces a bargain without either side having to trust the other. Bitcoin later added a narrow form of programmable money. Ethereum, which launched in 2015, made the programs general enough to do almost anything, and that is why most of the smart contracts you read about run on Ethereum or on chains built to copy its design.
Deploying one freezes the code forever
A developer writes the contract, most often in a language called Solidity. That code is compiled into bytecode and pushed to the blockchain in a special transaction. Once it lands, the contract has its own address, the way a wallet does, and anyone on the network can interact with it.
Here is the part that catches people off guard. After a smart contract is deployed, its code cannot be edited. It is frozen in place. If the developer left a mistake on line 40, that mistake is now permanent unless the contract was built with a deliberate escape hatch ahead of time. This is why careful teams pay for security audits before launch, and why some of the ugliest losses in crypto trace back to a single line nobody could reach back and fix.
Running a contract is not free. Every action costs gas, a fee paid in the chain's native token that pays the network for the computation. A plain transfer is cheap. A contract that grinds through heavy math or reads and writes a lot of stored data costs more. The fee is the meter, and it runs whether the call succeeds or fails.
How it differs from a paper contract
Both a smart contract and a written legal agreement exist to hold two parties to a deal. The way they get there could hardly be more different.
| Feature | Smart contract | Paper contract |
|---|---|---|
| Enforcement | Runs automatically in code | Needs courts or a middleman |
| Who holds the funds | The contract itself | A bank, escrow agent, or trustee |
| Changing the terms | Frozen once deployed | Amended by mutual agreement |
| Undoing a mistake | Rarely possible | A court can unwind it |
| When it works | Every hour, no staff | Business hours, human review |
| Cost to operate | A gas fee per action | Legal and admin fees |
The trade is speed and neutrality against flexibility. A smart contract will not play favorites and will not close for the weekend. It also will not show mercy if you fat-finger an address or if the code does something its authors never intended.
What people actually build
Most of the activity you hear about sits under one umbrella: decentralized finance, where smart contracts replace the middle office of a bank. Lending markets let you deposit one token and borrow another against it, with the interest rate set by code. Exchanges let you swap assets through a pool of funds rather than an order book staffed by humans. If you want the full picture of that world, start with our explainer on what DeFi is and how it works.
The reach goes well past trading. Stablecoins use contracts to mint and redeem dollar-pegged tokens. Non-fungible tokens are contracts that track who owns a given item. Bridges move value between chains through contracts that lock coins on one side and release them on the other, a design that has proven fragile enough that we wrote a whole piece on why bridges keep getting drained. Games, prediction markets, and on-chain organizations all run on the same foundation.
The code is the law, bugs and all
Because the code executes exactly as written, a flaw in the code is a flaw in the deal. There is no clause about intent and no judge to appeal to. Attackers know this, and they read contracts the way a locksmith reads a lock.
The numbers tell a story most people get backward. In the first half of 2026, crypto losses came to about 972 million dollars across 207 separate incidents, according to a report from TRM Labs. Smart contract exploits were the most common type by far, about 125 of those 207 events. Yet they accounted for only a small slice of the money. The catastrophic thefts, roughly 76 percent of all funds stolen, came from a different door entirely: stolen private keys and compromised infrastructure, which made up only around 15 percent of incidents. We unpacked that split in more detail in our look at why code bugs dominate the count but not the dollars.
A single case shows how fast it moves. In August 2026, the lending protocol Moonwell lost about 8.7 million dollars to an exploit and then had to freeze every one of its markets on the Base chain down to a single unit of value while it scrambled to respond, a scramble we covered in this breakdown of the Moonwell incident. The bug did not care that the code was audited or that real users had real money inside. It ran.
Staying on the safe side
You do not need to read Solidity to protect yourself, but a few habits help. When you use a DeFi app, you often grant a contract permission to spend your tokens, and that approval can sit open long after you have moved on. Old approvals are a standing risk, and you can and should cancel the ones you no longer use. Our guide on how to revoke token approvals shows the exact steps.
Beyond that, check whether a project has been audited and by whom, and treat anonymous teams with unaudited code as the gamble they are. Keep the bulk of your holdings in a wallet you never connect to experimental apps. Small habits like these will not stop a determined attacker from breaking a protocol, but they keep you out of the blast radius when one does.
FAQ on smart contracts
Can a smart contract be hacked?
The contract itself does exactly what its code allows. What gets exploited is a gap between what the developer meant and what the code actually permits. That gap is real and common, which is why audits, bug bounties, and slow rollouts exist.
Can you get your money back if a contract fails?
Usually not through any built-in process, since transactions are final and the code will not reverse itself. Recovery depends on the team offering to make users whole, an attacker returning funds, or, in rare cases, the community reaching a decision to intervene. None of that is guaranteed.
Do you need to code to use one?
No. Wallets and apps put a normal button-and-menu interface in front of the contract, so most users never touch the code. Understanding what the contract does before you approve it still matters, because you are the one signing.
Are smart contracts legally binding?
It depends on where you are and what the contract does. Some jurisdictions recognize code-based agreements, others do not, and the law here is still catching up to the technology. A smart contract can enforce a transfer on its own regardless of what a court would say about it afterward.
Smart contracts turned a blockchain from a ledger of balances into a place where money follows instructions without a human in the loop. That shift made on-chain lending, trading, and stablecoins possible. It also keeps a steady stream of exploit stories in the headlines. If you plan to use any of it, the practical next step is reading what a contract is allowed to do with your funds before you sign, starting with the approvals already sitting in your wallet.