Smart Contracts Explained
What a smart contract actually is
A smart contract is a program stored on a blockchain. It has an address (just like a wallet), it holds money, and it runs code when someone interacts with it.
The term describes executable software. Whether an interaction also creates a legal agreement is a separate question. Execution follows the program's rules, including any administrator permissions or external dependencies.
A simple example
Imagine a bet between Alice and Bob: "If it rains tomorrow, Alice pays Bob 1 ETH. If it does not rain, Bob pays Alice 1 ETH."
Without a smart contract, they need to trust each other. With a smart contract:
- Both Alice and Bob send 1 ETH to the contract
- The contract checks a weather data feed (called an oracle) the next day
- If it rained, the contract sends 2 ETH to Bob
- If it did not rain, the contract sends 2 ETH to Alice
- Settlement depends on the contract being funded, invoked, and supplied with valid weather data
Real smart contracts you use today
Uniswap - a decentralized exchange. Its smart contracts hold over $5 billion in tokens. When you swap ETH for USDC, you interact with a contract that calculates the price using a mathematical formula and executes the trade instantly.
Aave - a lending protocol. You deposit ETH into a smart contract and earn interest. Borrowers deposit collateral and borrow against it. The contract enforces all the rules: interest rates, collateral ratios, and liquidations.
OpenSea - an NFT marketplace. When you buy an NFT, a smart contract transfers the NFT to your wallet and the payment to the seller. No middleman handles the exchange.
What makes smart contracts different from regular programs
| Feature | Regular program | Smart contract |
|---|---|---|
| Runs on | Company's servers | Thousands of blockchain nodes |
| Can be changed | Through the application's update process | Deployed code is fixed; proxies can change the implementation |
| Can be paused | According to operator permissions | Depends on whether a pause mechanism exists |
| Transparency | Usually closed-source | Code is publicly readable |
| Access | Company decides who can use it | Anyone with a wallet can interact |
| Costs to run | Company pays server bills | Users pay gas fees per transaction |
The risks
Smart contracts are only as good as their code. A bug in a smart contract can be exploited.
The DAO hack (2016): A smart contract on Ethereum held $60 million in ETH. A hacker found a reentrancy bug that let them drain $50 million. This led to Ethereum splitting into two chains (Ethereum and Ethereum Classic).
How to reduce risk: Look for contracts that have been audited by firms like Trail of Bits, OpenZeppelin, or Certora. Check if the project has a bug bounty program. Start with small amounts. And remember: audits reduce risk but do not eliminate it.
Key takeaways
- Smart contracts are programs on a blockchain that run automatically when triggered.
- Their permissions, upgrade controls, and dependencies are part of their behavior.
- Real applications include exchanges (Uniswap), lending (Aave), and marketplaces (OpenSea).
- Bugs in smart contracts can lead to major losses - always check for audits.
- Oracles (like Chainlink) connect smart contracts to real-world data.
Quiz: Smart Contracts Explained
1 / 5What is a smart contract?