What Is a Smart Contract? Real Examples You Already Use

A smart contract is a program stored on a blockchain that runs automatically when its conditions are met. It follows simple “if this, then that” rules: if you send the right amount of one token, then the contract sends you another. Once deployed, nobody can quietly change how it behaves, and anyone can check what it does.

Despite the name, a smart contract usually isn’t a legal contract, and it isn’t especially smart. It’s closer to a vending machine: put in the right input, and the machine delivers the output without a shopkeeper. If you’ve ever held a stablecoin, swapped tokens or used a crypto app, you’ve already used one. This guide explains how they work, shows examples you’ll recognise, and covers the risks.

Illustration of a vending machine made of code: a coin goes in, an if-then rule checks it, and a token comes out
Input in, rules applied, output out. No middleman.

The vending machine idea

The term was coined by computer scientist Nick Szabo in the 1990s, years before blockchains existed. His favourite example was the vending machine: a machine that enforces a deal (money in, snack out) without anyone needing to trust a person.

Ethereum, launched in 2015, made the idea practical by letting anyone deploy programs on a public blockchain. As ethereum.org puts it, they follow “if this then that” logic and run exactly as written.

How a smart contract works

How a smart contract works, if this then that: if a user sends 100 USDC to a swap contract, then the contract checks the current price in its pool and sends back the matching amount of ETH, all in one transaction
Simplified example of a token swap contract.

A contract has three main ingredients:

  • Code: the rules, written by developers and published to the blockchain.
  • Its own balance: a contract can hold and send crypto, like an account controlled by its code instead of a person.
  • Functions you can call by sending it a transaction from your wallet.

When you interact with one, the network runs the code, and every node checks the result. Because the rules are on a public blockchain:

  • They’re transparent. Anyone can inspect the contract and its history on a block explorer.
  • They’re deterministic. The same input always gives the same result; nobody decides case by case.
  • They’re hard to change. Once deployed, the code generally can’t be altered. Some contracts are designed to be upgradeable, which means someone holds the keys to change them, and that’s worth knowing.

Running code costs computing work, so every interaction pays a network fee. What are gas fees? explains how that fee is calculated.

Smart contracts you may already use

Smart contracts you may already use: stablecoins such as USDC are token contracts, token swaps on decentralised exchanges, lending and borrowing apps, NFTs and digital collectibles, multisig wallets that need several approvals, and wrapped tokens such as wrapped bitcoin
Much of crypto beyond bitcoin itself runs on smart contracts.
  • Stablecoins. A token like USDC on Ethereum is a contract that keeps track of who owns how many tokens and lets holders send them. When you hold a stablecoin in your wallet, the contract’s records say so. What is a stablecoin? explains the rest of the picture.
  • Token swaps. Decentralised exchanges like Uniswap are sets of contracts holding pools of tokens. You send one token in and the contract sends another back, at a price set by the pool. Centralized vs decentralized exchanges compares that with using a regular exchange.
  • Lending and borrowing. Apps like Aave let users deposit crypto to earn interest or borrow against collateral. The contract enforces the rules, including selling collateral automatically if a loan becomes too risky.
  • Liquid staking. Tokens that represent staked ETH are issued and managed by contracts; see what is crypto staking?.
  • NFTs. Each NFT is a record in a contract that says which address owns which item.
  • Multisig wallets. Some wallets are contracts that require several people to approve a transaction, a common way for organisations to secure funds.

Even if you’ve only bought crypto on an exchange, the tokens you hold other than bitcoin very likely live in one.

What they can’t do

  • They can’t see the outside world on their own. A contract doesn’t know the price of gold or the result of a match. It relies on oracles, services that feed outside data onto the blockchain. If an oracle is wrong or manipulated, the contract acts on bad data.
  • They aren’t automatically legal agreements. Whether one creates legal obligations depends on the circumstances and the law where you are.
  • They can’t fix human mistakes. If you send tokens to the wrong contract or approve a malicious one, the code does exactly what it was told.

The risks

Code is written by people, and mistakes can be costly:

  • Bugs. A flaw in a contract can let attackers drain its funds. One of the earliest examples, The DAO hack in 2016, led to a split of the Ethereum blockchain. Audits reduce this risk but don’t eliminate it.
  • Admin keys. Upgradeable contracts can be changed by whoever holds the keys. That can be used to fix bugs, or abused.
  • Malicious contracts. Scam tokens and fake apps are contracts too. Approving one can let it move tokens out of your wallet, which is how wallet drainers work. Common crypto scams shows what to watch for.
  • Token approvals. Many apps ask for permission to spend your tokens. Unlimited approvals stay active after you’ve finished, so it’s worth reviewing and revoking old ones.

Smart contracts in one sentence

It’s a public program on a blockchain that holds and moves crypto according to fixed rules, without a middleman. That’s what makes stablecoins, decentralised exchanges and much of the rest of crypto possible, and why reading what you’re approving matters. For the foundation underneath it all, see how blockchain works, and for how apps keep costs down, what is a layer 2?.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top