A smart contract is not a microservice. This lesson recalibrates your backend instincts: where code lives, who pays to run it, and why "calling a function" sometimes costs money and sometimes is free.
view function," you need to know exactly what each means. This is the vocabulary of every technical conversation you'll have.
Ethereum is a single state machine replicated across thousands of nodes. The state is a giant key→value map of every account and its data. A transaction is a signed request to change that state; when a block is produced, every node re-executes every transaction in it and updates to the identical new state. The component that runs the code is the EVM (Ethereum Virtual Machine).1
Mental swap: not "my server runs my code," but "the whole network runs the same code in lockstep, and agrees on the result." That redundancy is the cost you pay for trustlessness (Lesson 1).
This distinction is foundational — many people never learn it cleanly.
Key consequence: nothing happens on-chain without an EOA kicking it off. A contract can't wake up on a timer. Your tokenized-fund contract just sits there until someone sends a transaction to it. (Automation — "pay coupons monthly" — therefore needs an off-chain trigger or a keeper service. Another off-chain dependency to design.)
A smart contract is code + persistent storage living at an address. You deploy it once (a transaction that creates a contract account), and thereafter anyone can call its public functions. Here's a stripped-down one — read it as an engineer:
// Solidity — a minimal ownership ledger contract ShareRegistry { // persistent on-chain storage: address → share count mapping(address => uint256) public balances; address public transferAgent; // the accountable party function transfer(address to, uint256 amount) public { require(balances[msg.sender] >= amount, "insufficient"); balances[msg.sender] -= amount; // state change → costs gas balances[to] += amount; } function balanceOf(address who) public view returns (uint256) { return balances[who]; // reads only → free to call } }
Two things to notice. transfer modifies storage → it must be a transaction, mined into a block, and it costs gas. balanceOf only reads → marked view, it can be answered by any single node for free, no transaction needed. msg.sender is the authenticated caller — the chain proves who it is via their signature (no req.user to spoof).
Every EVM operation has a fixed gas cost (storage writes are expensive; arithmetic is cheap). When you send a transaction you pay gas used × gas price in ETH. Three reasons this exists:
| Purpose | Why it matters to you |
|---|---|
| Halting / DoS protection | An infinite loop simply runs out of gas and reverts. The network can't be frozen by bad code. |
| Resource pricing | Storage is scarce (every node stores it forever) so it's costly. This is why architects push data off-chain — on-chain storage is the most expensive resource you have. |
| Fee market | When the network is busy, gas price rises. Cost predictability becomes a real platform concern — and a reason institutions look at cheaper L2s or permissioned chains. |
If a transaction runs out of gas or hits a failed require (like the "insufficient" check above), it reverts: every state change is rolled back as if it never happened — but the gas spent up to that point is not refunded. Transactions are atomic. There is no half-completed transfer. (This is a feature you'll lean on: compliance checks that fail simply revert the whole transfer.)
view vs state-changing is the line between "free query" and "costs money + needs consensus." Reporting/dashboards read; only real ownership changes transact.From memory. Interleaves one Lesson-1 idea on purpose.
view) function changes no state, so any node can answer it directly — no transaction, no gas, no consensus needed.view function is free to call.require reverts all state changes as if nothing happened, but the gas burned up to that point is lost.Skim, then bookmark: Ethereum.org — Accounts and Gas & Fees. These two pages are the authoritative version of everything above. (Out of scope for now: gas-optimisation tricks and EIP-1559 fee mechanics — you need the model, not the dial-tuning.)