Just in
TechXbox Game Pass November Additions: 3 More Games, 8 Leaving Nov. 30TechUbisoft Motherbrain AI Unit Launches as H1 Net Bookings Fall 16.5%AIChatGPT Space Rolls Out to Plus Users, Replacing the Library TabTechAnthropic IPO Closes With $119.5 Billion in Combined Gross ProceedsAIRiemann Hypothesis Proof Certified by Lean and Mathlib CommunitiesTechCairn AI Agents Found a Zero-Day in MONAI Label, Amazon Says
Crypto · Guide

What Is a Smart Contract? How Blockchain Code Runs Deals by Itself

A smart contract is a program on a blockchain that carries out an agreement automatically. Here is how it works, where you already use one, and what it cannot do.

USA Publishing Group6 min read
Share
Computer circuit board with a glowing blue light, a stand in for the code that runs a blockchain smart contract
Photo: Deng Xiang / Unsplash

Key takeaways

  • A smart contract is code stored at its own blockchain address that runs automatically when a transaction calls it, with no person controlling it.
  • Smart contracts cannot read outside data on their own, so they depend on oracles, and a wrong or manipulated feed leads to wrong results.
  • Approving a contract call in your wallet gives that code permission over your tokens, so check the amount, the address and your old approvals.
In this story 5 sections
  1. How a smart contract works, using a vending machine
  2. Where you run into smart contracts without noticing
  3. What smart contracts cannot do
  4. Common myths about smart contracts
  5. What to do with this before your next crypto app

A smart contract is a small program stored on a blockchain that carries out the terms of a deal by itself once the right conditions are met. If you searched "what is a smart contract" after an app asked you to "approve a contract call," that is the thing you are being asked to trust. Nobody presses a button on the other side. The code runs, and the result is recorded for good.

How a smart contract works, using a vending machine

The comparison most people start with comes from computer scientist Nick Szabo, who described the idea in the 1990s. Think of a vending machine. You put in the right amount of money, you choose a snack, and the machine hands it over. The rules are built into the machine.

ethereum.org uses the same picture, boiled down to "money plus snack selection equals snack dispensed." A smart contract works like that, only the machine is code and the snacks are usually tokens or crypto.

Here is what happens under the hood on Ethereum, the network where most smart contracts live:

  • It lives at an address. A contract is its own account on the blockchain, with a balance, a set of functions and some stored data. Unlike your wallet, no person holds the keys to it.
  • You trigger it with a transaction. When you swap a token or deposit into a lending app, your wallet sends a transaction that calls one of the contract's functions.
  • Every node checks the result. Many computers across the network run the same code and agree on the outcome, so no single company can fake it.
  • You pay a fee to run it. Each step costs computing work, paid as a gas fee. Complex contracts cost more to use than a simple transfer.
  • It is usually permanent. By default a deployed contract cannot be deleted, and transactions it processes cannot be reversed.

Developers write these programs in languages built for blockchains, most often Solidity or Vyper, then compile and publish them. Anyone with enough ETH to cover the deployment fee can do it, which is both the appeal and part of the risk.

If the idea of a shared ledger is still fuzzy, our guide to what a blockchain is covers the foundation this all sits on.

Where you run into smart contracts without noticing

Most people use smart contracts without ever reading one. Coinbase's explainer names a few well known examples, and they show how broad the idea is:

  • Swapping tokens. Decentralized exchanges like Uniswap are collections of contracts that trade one token for another from shared pools, with no company matching orders.
  • Borrowing and lending. Apps such as Compound hold deposits and issue loans automatically based on collateral rules. This is the core of DeFi.
  • Stablecoins. USDC, the dollar pegged stablecoin, is issued and moved through a smart contract.
  • NFTs and games. Who owns a digital collectible is tracked by a contract, as explained in our NFT guide.
  • Shared wallets. A "multisig" contract only releases funds when, say, three of five people sign off.

The one place you see smart contracts directly is your wallet. When a site asks you to connect and then approve a "contract interaction" or token spending permission, you are giving a specific contract the right to do something with your funds. That moment matters more than most people realize.

What smart contracts cannot do

The word "smart" oversells it. A 2018 primer from the CFTC's LabCFTC team called the name possibly an oxymoron, because the contract is only as good as the code and the data feeding it. A few hard limits follow from that.

They cannot see the outside world. A contract on Ethereum has no way to check a stock price, a sports score or the weather on its own. It relies on services called oracles to deliver that data. If the oracle is wrong or manipulated, the contract will act on bad information with total confidence.

They do exactly what the code says, not what the author meant. A typo or logic flaw becomes a feature anyone can use. Many of the largest crypto thefts were not hacks of a blockchain itself, but attackers calling a contract in a way its developers never expected.

They are hard to fix. Because a deployed contract usually cannot be changed, a bug can stay live. Some projects add upgrade switches, but that means someone holds the power to change the rules, which brings back the trusted middleman the contract was supposed to remove.

They have size and cost limits. ethereum.org notes a maximum contract size of 24KB, and every action costs gas. That is why big apps are split into many contracts that call each other.

Common myths about smart contracts

Myth: a smart contract is a legal contract. Not necessarily. The CFTC primer points out that one may or may not meet the legal test of a binding agreement, depending on the facts. Existing laws still apply either way, including securities, commodities, tax and anti money laundering rules.

Myth: if the code is public, it must be safe. Public code means anyone can inspect it, not that anyone did. The same CFTC document lists hidden malicious code, insider "kill switches" and contracts that do not behave as advertised among the fraud risks.

Myth: an audit means zero risk. An outside review lowers the odds of a disaster, but audited contracts have still lost money to bugs and oracle tricks.

Myth: you can call support if something goes wrong. In most cases there is no one to call. A transaction a contract processed is final, and the CFTC notes that limited recourse means a total loss is possible.

What to do with this before your next crypto app

Knowing how these programs work changes how you should treat that approval pop up in your wallet. A few habits help:

  1. Read what you are approving. Many wallets show whether a request lets a contract spend a set amount of a token or an unlimited amount. Pick the smaller amount when you can.
  2. Check the contract address. Scam sites copy real apps and point you to look alike contracts. Go to the app through a bookmark, not a link from a message or ad.
  3. Review old approvals. Permissions you granted months ago can still be active. Most wallets and block explorers let you see and revoke them.
  4. Keep large balances separate. Use one wallet for trying new apps and another, ideally a hardware wallet, for savings. Our guide on how crypto wallets work explains the options.
  5. Treat high yields as a warning. A contract promising returns far above normal is often the bait, not the product.

For more plain English explainers on coins, tokens and the apps built on them, browse the crypto section. And the next time a wallet asks you to sign a contract call, pause for ten seconds and ask what that code will be allowed to do with your money.