In this track: Meet smart contracts
beginner · 3 MIN READ

A counter as a contract

A small state variable and one rule make execution easier to picture.

LET’S PICTURE IT

A classroom tally can remember a number and allow an agreed action to increase it by one.

SEE IT FOR YOURSELF
A valid counter call, step by stepStep 1 / 4
A valid counter call, step by stepFunction requestincrement()No argumentsBefore executionstored count0A local teaching example with a defined starting stateIncoming callCheck function dispatchCheck coded conditionsRules passConditions passContinue executionA failed check can revert insteadCalculation0 + 1Result: 1Storage writecount = 1Persists if call succeedsCalculating a local value and storing it are separate stepsPersistent statecount1Later readGetter reports 1No new incrementState, logs and browser display have different roles

This example begins with count zero and a request to call increment(). No real contract is deployed.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Start with remembered state

Imagine a contract with a stored count of zero. Storage persists between calls, unlike a temporary calculation in one execution. The count is a value associated with this contract’s state.

Define a transition

A function named increment adds one to the count. Calling it twice in accepted successful transactions changes zero to one and then two. Nodes check the specified rule rather than trusting a website’s displayed number.

Read without changing

A getter can report the current count through a read simulation. Reading the value does not itself increment it. The same function name in an interface and an onchain state change are different parts of the system.

Try the local model

The button above changes a browser-only counter according to the same simple rule. It uses no wallet or network. Once the rule makes sense, read about function arguments and how an ABI turns the request into bytes.

QUICK CHECK · NO PRESSURE

Does reading a counter automatically increase it?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.