Part II · Accounts, transactions, contracts
Smart contracts and the EVM
Think of a contract as a vending machine with public rules, not as a paper contract that is automatically legally binding.
A vending machine
A vending machine hands out the item when it receives the right payment and its conditions are met; otherwise it gives the money back. A smart contract likewise turns rules into a program that is deployed on-chain and executed the same way by every node.
While executing a transaction, the Ethereum Virtual Machine (EVM) reads state, checks conditions, updates state, or rolls back when a check fails. It does not go online to read today’s weather, and it cannot tell whether goods were really shipped: that is the oracle problem from Chapter 4.
Reads and writes
- Reading (for example, asking the Counter for its current number) is usually an
eth_callthrough RPC, executed locally on a node: no signature, no gas, no change to on-chain state. - Writing (for example, calling
increment) requires signing and sending a transaction; state changes only after it is mined, and it costs gas. - When a check fails, such as a
requirein the code, the transaction reverts: none of the state changes from that execution are kept, but the gas has already been spent.
| Observation | What it means |
|---|---|
| Transaction succeeded | The EVM execution did not revert |
| Counter value increased | A value in the contract’s storage changed |
| Event log (if the contract emits one) | Lets interfaces and indexers follow along; it does not replace reading state directly |
| Gas paid | Keeping one shared state has an execution cost |
Simulate first, then broadcast
Every on-chain transaction in this book was first simulated with viem using eth_call and estimateGas, and where needed eth_simulateV1 or stateOverride. Simulation does not change the chain: it uses no nonce and spends no ETH. Only a transaction that is actually broadcast after confirmation changes on-chain state.
Frozen once deployed
Once an ordinary contract is deployed, its code is fixed at that address. It cannot be patched or extended later. To change the logic there are only two routes:
- deploy a new contract and get everyone to agree to use the new address; or
- use an upgradeable pattern such as a proxy, decided at deployment time (Chapter 13).