Glossary
Smart contract
A program stored on a blockchain that runs automatically when called and cannot easily be changed; the basis of tokens, DeFi and NFTs.
On this page
A smart contract is a computer program that lives on a blockchain. Anyone can call it by sending a transaction, and every computer on the network runs the same code and agrees on the result. Once deployed, the code generally cannot be altered. Despite the name, it is not necessarily a legal contract, and it is not intelligent: it does exactly what the code says.
Ethereum made smart contracts practical in 2015, and most blockchains launched since then support them.
What they make possible
- Tokens. A token is a contract that keeps a ledger of who owns how many units. Stablecoins work this way.
- Decentralized finance. Exchanges, lending pools and derivatives that run with no company holding customer funds.
- NFTs. Records of ownership of unique items.
The trade-offs
- Code is final. A bug cannot be fixed with a phone call. Flaws in contracts have led to thefts of hundreds of millions of dollars at a time, and stolen funds are rarely recovered.
- "Immutable" has exceptions. Many contracts include administrator keys that can upgrade the code or pause it. That allows fixes, and also means someone must be trusted.
- Outside data is a weak point. A contract cannot see the real world. It relies on "oracles" to supply prices, and a manipulated price feed can drain it.
- Every action costs a gas fee.
- Approvals. Using an application usually means granting a contract permission to move your tokens. A malicious or compromised contract can abuse that permission, which is a common way wallets are emptied.
An audit by a security firm lowers the risk of bugs and does not remove it.
