Skip to content

Smart Contracts Explained: How They Work on Ethereum

5 min read

Glass vending machine dispensing a token, illustrating a smart contract on Ethereum
By · Last updated

Smart contracts explained in two sentences: a smart contract is a program stored on a blockchain that runs exactly as written when a transaction calls it. On Ethereum, nobody approves each run, and nobody can quietly edit the rules afterwards (with exceptions we cover below). That is the appeal, and it is also the risk.

A glass vending machine with coins going in and a token coming out
A smart contract works like a vending machine: fixed rules, no clerk.

Key takeaways

  • A smart contract is code plus stored data at an Ethereum address. It executes when a transaction calls it.
  • It is not “smart” and not automatically a legal contract. It does what the code says, bugs included.
  • Before you use one, read its verified source, check who can change it, and review what permissions you grant.

Last reviewed: December 2026, by our editorial team.

What a smart contract is

Think of a vending machine. You put in a coin, press a button, and the machine either gives you a snack or it doesn’t. No clerk decides.

A smart contract is the same idea in code. The term goes back to the cryptographer Nick Szabo, who used the vending machine comparison in the 1990s. Ethereum made it practical.

The contract has functions (the buttons) and stored data (balances, owners, game state). Anyone can call its public functions, and the result follows only from the code and the inputs.

One limit to know early: a contract cannot look up outside facts, such as a price or a sports score, on its own. It needs a data feed (an oracle), and that feed becomes part of what you trust.

How a smart contract is executed

First, a developer compiles the code and sends a deployment transaction. Ethereum records the contract at a new address, and from then on it sits there on the network.

To use it, you sign a transaction from your wallet that targets that address and names a function. Validators include the transaction in a block, and every node runs the contract code in the Ethereum Virtual Machine (EVM). If every step succeeds, the new state is saved. If anything fails, the whole call reverts, though you still pay for the work done. Our Ethereum blockchain overview covers the network layer underneath.

Gas and the EVM

Every EVM operation costs gas, a unit of computation. Your fee is gas used multiplied by the price per unit, paid in ETH. A plain ETH transfer uses 21,000 gas; a contract call uses more, depending on how much code runs and how much data it writes.

A hypothetical example: at a price of 20 gwei per unit, a 21,000-gas transfer costs 0.00042 ETH. The 20 gwei is illustrative, not a current quote. A contract call using 100,000 gas at the same price would cost five times as much.

The price moves with network demand, so the same action can cost different amounts on different days. You can estimate a cost with our Ethereum gas fee calculator. A failed call still costs gas, so a wallet warning like “this transaction will likely fail” deserves attention.

Examples: tokens, games, staking

Use What the contract does What to check
Token (ERC-20) Keeps a ledger of who holds how many tokens and lets holders transfer them Can the owner mint more or freeze balances?
Game DApp Holds stakes, applies rules, pays out results Where does randomness come from, and who can pause payouts?
Staking Locks deposited tokens and tracks rewards owed How are rewards funded, and can you withdraw at any time?

For games, we walk through what happens when you press play and how provably fair results are checked. For deposits, our DAB staking page describes the mechanism. Treat it as a summary and read the contract itself to confirm.

Limits: bugs, immutability, no intent

Code does what it says, not what the author meant. A logic error is executed faithfully, and because blockchain transactions cannot be reversed, lost funds usually stay lost.

Can a smart contract be changed after deployment? The deployed code itself cannot. But developers often use a proxy pattern: a fixed front address forwards calls to a logic contract that an admin can swap. That allows bug fixes. It also means someone holds power over your funds. Find out whether a contract is upgradeable and who holds the admin key.

Are smart contracts legally binding? Not by default. A contract is code; whether it also counts as a legal agreement depends on the jurisdiction and the circumstances. Some US states have passed laws recognizing blockchain records and smart contracts in electronic transactions, but that does not settle every dispute. For a specific situation, ask a qualified lawyer.

How to check a contract before using it

You can do most of this yourself with a block explorer such as Etherscan:

  1. Get the contract address from the project’s official site, then compare it against a second source. Fake copies exist.
  2. Open the address and look for a “verified” source code tag. Unverified code means you cannot read what you are trusting.
  3. Look for admin functions: pause, mint, upgrade, withdraw. Note who the owner address is.
  4. Look for an audit report, and confirm it names this exact address. An audit lowers risk but does not remove it.
  5. Test with a small amount first, and check the token approvals you grant. Approve only what you need.

Set up your wallet carefully first; our wallet setup guide covers it. Never share your seed phrase or private key with anyone, including a site or support chat.

Risk note

Smart contracts can contain bugs, be exploited, or be controlled by an admin. You can lose all funds you deposit. This article is general education, not investment, tax, or legal advice.

Data sources

  • Ethereum.org — Introduction to smart contracts — Definition of smart contracts and how they run on Ethereum, as of December 2026.
  • Ethereum.org — Gas and fees — How gas is calculated and paid, including the 21,000 gas base cost of a transfer, as of December 2026.

Keep reading