In this track: Write and read Solidity
advanced · 7 MIN READ

Read your first Solidity contract

Variables hold values. Functions describe the changes you allow.

LET’S PICTURE IT

A contract is a small rulebook plus a notebook. Functions are the rules; state variables are what it remembers.

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 a counter

A minimal example declares uint256 public count; and a function increment() external { count += 1; }. uint256 is a non-negative integer type. public creates a getter so callers can read count. external means the function is part of the callable interface.

Reads and writes

A view function promises not to modify state through that execution. A pure function does not read or modify contract state. A local read can be simulated without sending a paid transaction. Calling a view function from another onchain transaction still uses execution gas.

Permissions are code

If only an owner should change a setting, the code must enforce that condition. A friendly button or hidden menu is not access control. Anyone can construct calldata and attempt to call an exposed function.

Compilation connects the pieces

The compiler produces bytecode for the EVM and an ABI for applications. Our counter visual is an educational model, not a deployed Solidity compiler. Continue with ABI encoding to see exactly what a function request looks like.

QUICK CHECK · NO PRESSURE

Can hiding a button secure a public function?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

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