A smart contract is a program stored on the blockchain that executes automatically when predetermined conditions are met. Once deployed, its code cannot be changed (unless specifically designed with upgrade mechanisms), and its execution is verified by every node on the network. It removes the need for a trusted intermediary by making the rules transparent and enforcement automatic.

What Is a Smart Contract?

3 min read

The short version

A smart contract is a vending machine for agreements. You put in the right inputs (coins + selection), and the machine automatically delivers the output (snack) without a shopkeeper. The rules are visible (the price list), enforcement is mechanical (no negotiation), and once deployed, the machine works exactly as built, nobody can secretly change the prices or steal the snacks without everyone seeing.

How It Works

Smart contracts on Ethereum are written in Solidity (or Vyper), compiled to EVM bytecode, and deployed to a specific address via a transaction. The contract has: (1) State variables, data stored permanently on-chain (balances, mappings, settings). (2) Functions, logic that reads/modifies state or sends ETH. (3) Events, logs emitted for off-chain indexing. When someone calls a contract function (via a transaction), every validator executes the bytecode, updates state identically, and reaches consensus on the result. The contract's behavior is deterministic, given the same state and input, every node produces the same output. Common patterns: token contracts (ERC-20), NFT contracts (ERC-721), lending protocols (Aave, Compound), decentralized exchanges (Uniswap), and governance systems.

How a simple escrow smart contract works

Alice wants to buy a digital asset from Bob but does not trust him to deliver. They use an escrow contract: (1) Alice deposits 1 ETH into the contract. The contract's state now shows: buyer=Alice, seller=Bob, amount=1 ETH, status=AWAITING_DELIVERY. (2) Bob delivers the asset off-chain and marks delivery in the contract. Status changes to AWAITING_CONFIRMATION. (3) Alice confirms receipt by calling confirmDelivery(). The contract automatically sends 1 ETH to Bob. If Alice does not confirm within 30 days, Bob can claim the funds. If there is a dispute, a pre-agreed arbitrator (a third address) can resolve it. All rules were visible before Alice deposited, no surprises, no middleman fees beyond gas.

What People Get Wrong

  • Smart contracts are legally binding contracts

    The word "contract" is a programming metaphor. A smart contract is code that auto-executes. It may or may not have legal standing depending on jurisdiction, most legal systems have not fully addressed this. They enforce code rules, not legal rules.

  • Smart contracts can access real-world data directly

    They can only access data on their own blockchain. To get external data (prices, weather, sports scores), they need oracles, trusted data feeds that write external information on-chain. The contract itself cannot make API calls.

  • All smart contracts are safe to use

    Smart contracts can contain bugs, backdoors, or malicious logic. A contract being "on the blockchain" does not make it trustworthy, it makes it transparent and verifiable. You should only interact with audited contracts or those you (or someone you trust) have reviewed.

  • Smart contracts cannot be upgraded

    By default, deployed bytecode is immutable. However, proxy patterns (UUPS, Transparent Proxy) allow the logic to be swapped while keeping the same address and state. Whether upgradeability is good or bad depends on context, it trades immutability for bug-fixability.

Sources & Further Reading

Questions People Also Ask

What language are smart contracts written in?
On Ethereum: primarily Solidity (C-like syntax, most popular) and Vyper (Python-like, simpler by design). Other blockchains use Rust (Solana, Near), Move (Aptos, Sui), or Cairo (Starknet). The compiled output is bytecode specific to each chain's virtual machine.
How much does it cost to deploy a smart contract?
Deployment gas depends on contract size and complexity. A simple token contract might cost 1-3M gas (~$30-$100 at typical gas prices). A complex DeFi protocol with multiple contracts can cost $5,000-$50,000+ in deployment gas. This is a one-time cost.
Can smart contracts hold ETH and tokens?
Yes. Smart contracts have their own addresses and can hold any amount of ETH or tokens. Major DeFi contracts hold billions of dollars. The contract's code determines under what conditions those funds can be moved.

More in Smart Contracts & Ethereum

See all →
Was this page helpful?

Page last checked