Hashtag Web3 Logo

Smart Contracts Explained

10 min
beginner

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 name is misleading. It is not smart (it does exactly what the code says, nothing more) and it is not a legal contract (it is software). Think of it as an automatic vending machine: you put in money, the machine follows its rules, and something comes out. No negotiation. No judgment calls.

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:

  1. Both Alice and Bob send 1 ETH to the contract
  2. The contract checks a weather data feed (called an oracle) the next day
  3. If it rained, the contract sends 2 ETH to Bob
  4. If it did not rain, the contract sends 2 ETH to Alice
  5. Neither party can cheat or refuse to pay
  6. Alice Sends 1 ETH Bob Sends 1 ETH Smart Contract Holds 2 ETH Checks weather oracle Weather Oracle ☔ Rained → 2 ETH to Bob Automatic, no dispute ☀ Sunny → 2 ETH to Alice Automatic, no dispute

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

FeatureRegular programSmart contract
Runs onCompany's serversThousands of blockchain nodes
Can be changedYes, the company pushes updatesNo (code is permanent on-chain)
Can be shut downYes, by the companyNo (runs as long as the blockchain exists)
TransparencyUsually closed-sourceCode is publicly readable
AccessCompany decides who can use itAnyone with a wallet can interact
Costs to runCompany pays server billsUsers 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.
  • They are permanent, transparent, and unstoppable.
  • 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 / 5

What is a smart contract?