Smart Contract
A smart contract is a program stored on a blockchain that runs automatically when its conditions are met; bugs in the code are a real risk to funds held in it.
A normal contract needs people to honour it and courts to enforce it. A smart contract enforces itself: the rules are code, and the blockchain runs them. That makes DeFi, stablecoins and tokens possible — and it also means a single bug can drain millions with no one able to undo it.
- Category
- Cryptocurrency and Blockchain
- Reading time
- 4 min
- Also called
- Self-executing contract, On-chain program, Contract account
- Updated
Smart contracts in plain words
A smart contract is a bundle of code and data placed on a blockchain through cryptographically signed transactions.1
ethereum.org compares it to a vending machine: specific inputs guarantee predetermined outputs.2 The code runs according to its rules and cannot be changed once created.2
That also means mistakes are hard to fix: deployed code usually cannot be patched, and stolen assets are mostly irrecoverable.3 See Stablecoin and Liquidation.
How a smart contract works, step by step
Write the code
A developer writes the rules as a program.
Deploy it
The code and data are deployed on the blockchain with a signed transaction.1
Send a transaction
A user calls the contract, for example to swap or deposit.
Check conditions
The contract follows its 'if this then that' rules.2
Execute automatically
If conditions are met, the result is predetermined, like a vending machine.2
Record publicly
Anyone can track the transfers on the public blockchain.2
Worked examples
Example 1 — An escrow
Rules run automaticallyA contract holds 1,000 USDC and pays the seller when the buyer confirms delivery, or refunds the buyer after 30 days.
| If confirmed | Seller receives 1,000 USDC |
| If no confirmation by day 30 | Buyer refunded 1,000 USDC |
Specific inputs guarantee predetermined outputs.2
Example 2 — Automatic liquidation
Liquidated at $4,900A lending contract liquidates a loan if collateral falls below 125% of the debt. Debt is $4,000.
| Liquidation level | $4,000 × 1.25 = $5,000 |
| Collateral now | $4,900 → liquidated |
The contract follows its coded rules with no human decision.2
Example 3 — A bug
−$2,000,000A contract holding $2,000,000 has a flaw that lets an attacker withdraw funds.
| Funds drained | $2,000,000 |
| Patch the deployed code? | Usually not possible |
Attackers seek to exploit vulnerabilities in smart contracts, and stolen assets are mostly irrecoverable.3
Smart contract vs. traditional contract
| Aspect | Smart contract | Traditional contract |
|---|---|---|
| Enforced by | Code on a blockchain | People and courts |
| Speed | Automatic | Can take days or years |
| Changes | Usually cannot be changed | Can be amended by agreement |
| Mistakes | Hard or impossible to reverse | Can be disputed |
Where smart contracts are used
Decentralised exchanges
Pools that swap tokens.
Lending
Collateralised loans with automatic liquidation.
Stablecoins
Issuing and redeeming tokens.
Token creation
Defining supply and transfers.
Advantages and disadvantages
Advantages
- Run automatically without intermediaries.
- Rules are public and predictable.
- Anyone can check the transactions.
- Available 24/7.
Disadvantages
- Bugs can drain funds.
- Deployed code is hard to fix.
- Stolen funds are rarely recovered.
- Legal status differs by country.
Going deeper
Read as far as you need. Each level builds on the one before it.
Code that runs itself
Beginner
Immutable rules
Intermediate
Contracts execute according to their code, which cannot be changed once created.2 That gives certainty, but also rigidity.
Common mistakes
Assuming 'audited' means safe
Audits can miss bugs.
Approving unlimited spending
Letting a contract move all your tokens.
Ignoring upgrade keys
Not checking who can change a contract.
Trusting copycat contracts
Using a fake contract with a familiar name.
Check your understanding
Test yourself before moving on. Each answer comes with an explanation.
Key points to remember
- A smart contract is a program on a blockchain.
- It runs automatically when conditions are met.
- Its rules are public and usually cannot be changed.
- Bugs can drain funds.
- Stolen funds are rarely recovered.
Frequently asked questions
Are smart contracts legally binding?
Can a smart contract be changed?
Do I need to code to use one?
Further learning
- Liquidation
An automatic contract action traders meet.
- Stablecoin
A major use of smart contracts.
- Counterparty Risk
Code risk vs company risk.
- Settlement
How on-chain transactions settle.
Sources
This article is written in our own words. The sources below support the specific facts, rules and figures marked with a number in the text. Links open the original publisher’s page.
- NIST CSRC Glossary. Smart contract (opens in a new tab) Checked .
- ethereum.org. Introduction to smart contracts (opens in a new tab) Checked .
- ethereum.org. Smart contract security (opens in a new tab) Checked .
Educational content, not financial advice. Examples use hypothetical prices and simplified costs; actual fees, margin rules and regulations vary by broker, market and country. We are not affiliated with any publisher linked above. Last reviewed . Report an error or request a source credit.