Track 4 · Solidity foundations · lesson 1

Read before you write

8 min


You are not going to write anything this lesson. You are going to read a finished contract, decide what it does, and then watch it run.

Reading code you did not write is the actual job. Starting with a blank file is how most courses lose people on day one.

Everything below is real. The compiler running in your browser is the same solc that compiles contracts holding billions of dollars, and the machine executing it is a real EVM. Nothing here is a simulation, and nothing costs anything.

The contract

Counter.solPredict
Loading editor…
Read it, predict what happens, then run it.
Run the code to see what happens.

What you are looking at

Predict

Nobody set count to anything. What is it before the first call to increment?

Choose one answer

The part that should feel strange

increment() is public. There is no caller check anywhere.

Anyone in the world can call this function, as many times as they like, and change the contract's state. That is not an oversight in the example — it is the default, and it is why access control gets its own lesson later.

Check

The tests called increment() three times and count became 3. Where was that value between the calls?

Choose one answer

Worth remembering

  • A contract is like a class whose fields live permanently on-chain.
  • `public` on a state variable generates a getter function of the same name.
  • There is no null: numbers start at 0, booleans at false, addresses at the zero address.
  • Functions are callable by anyone unless you explicitly restrict them.
  • State survives between calls only because it is in storage.