A vending machine, not a salesperson
Picture a vending machine. You drop in a coin, press a button, and a drink rolls out — no clerk, no negotiation, no chance of the machine changing its mind. The rules are baked into the metal: *if* the right money goes in, *then* the right product comes out. The machine doesn't trust you and you don't have to trust it; you both just trust the mechanism, which behaves the same for everyone, every time.
A smart contract is a vending machine made of code. It is a small program that lives permanently at an address on a blockchain like Ethereum, holding its own funds and its own memory. When you send it a request, it runs its built-in rules and updates the shared ledger — automatically, with no company or person in the loop. We moved from a chain that only moves money to one that runs programs.
Code plus state, living at an address
An ordinary wallet is controlled by a private key held by a human. A contract is different: it is an account with no key and no owner, controlled only by its own code. Two things live at its address: the code (the rules, fixed forever once deployed) and the state (its current memory — balances, settings, who voted, whatever the program tracks). Each time the contract runs, it may read and rewrite that state, and the new values are recorded on-chain for all to see.
Developers usually write this code in Solidity, a language built for the job. Here is about the smallest contract worth showing: a shared counter that anyone in the world can nudge upward, and that never forgets its total.
contract Counter {
uint public total; // STATE: lives on-chain forever
function increment() public { // a rule anyone can call
total = total + 1; // read state, write new state
}
}
// Deploy once -> the contract gets a permanent address.
// Anyone, anywhere can call increment(). The new
// total is agreed on by the whole network.Every node runs it, identically
Here is the part that makes contracts trustworthy. When you call `increment()`, your request doesn't run on one machine somewhere. It runs on every full node in the network, inside a shared sandbox called the Ethereum Virtual Machine (the EVM). The EVM is a tiny, strictly deterministic processor: feed it the same code and the same starting state, and it produces the same answer on every computer on Earth.
Because thousands of independent machines all run the same step and all reach the same total, no single one of them can cheat. If one node lied about the result, its answer would simply disagree with everyone else's and be thrown out. This is why people call Ethereum a world computer: not a fast one, but one whose every step is checked by the entire network and recorded permanently.
Running code on thousands of machines isn't free, so every operation carries a small price tag paid in a gas fee. The trace below shows the EVM charging gas as it walks through our `increment()` call. Cheap actions cost a little; touching permanent storage costs the most, because every node must keep that change forever.
Calling increment() -- the EVM charges gas per step
step operation gas
---- --------- ----
1 load current total from storage ~2100
2 add 1 to it ~3
3 store new total back to storage ~5000
4 done
total ~ 7100 gas
You pay (gas used) x (gas price) as the fee.
Reading is cheap; writing storage is the costly part.What becomes possible
Once you can attach automatic rules to money, a huge space opens up. A contract can hold funds in escrow and release them only when a condition is met; it can run an auction that pays out the moment it ends; it can mint a fixed-supply token, share a treasury among thousands of strangers, or split royalties to a dozen artists on every sale — all without anyone needing to be trusted to press the button. The rule is the button, and it presses itself.
Contracts can also call one another, snapping together like Lego bricks: one contract's output becomes another's input, and whole applications grow from small composable pieces. When a contract pairs with a website front-end that ordinary people can click, the result is a decentralized app — software whose core logic runs on the shared world computer instead of a company's private servers.
Public and permanent: the double-edged sword
Two qualities give contracts their power, and the same two demand respect. First, a contract is fully public: its code and its entire state are visible to anyone, so its rules can be inspected and verified rather than taken on faith. Second, once deployed it is effectively immutable — the code can't be edited, and not even its author can quietly change it. That is exactly what lets strangers rely on it: it will do tomorrow precisely what it does today.
The takeaway
A smart contract is just code plus state living at an address, run identically by every node so that no one has to be trusted. That single idea turns a ledger of payments into a programmable world computer — where rules enforce themselves, applications compose like building blocks, and everything is open for anyone to check.
Next we'll zoom in on the engine that actually runs all this — the Ethereum Virtual Machine and the gas that meters it — to see exactly how the network charges for computation and keeps every node honest.