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

A Solidity source file explained

Separate metadata, compiler constraints and declarations before reading function logic.

LET’S PICTURE IT

A recipe can have a license, an equipment requirement and the actual instructions as separate parts.

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 at the file header

An SPDX comment declares licensing information for the source. A pragma constrains compatible compiler versions; it does not download or select the compiler by itself.

Find the declarations

Contracts, interfaces, libraries and other declarations describe program structure. A contract can contain persistent variables, functions, events, errors and modifiers.

Read code in context

A fragment may depend on imported types or inherited behavior. Do not assume the visible function is the entire implementation of its permissions or storage layout.

Connect to build artifacts

Compilation produces an ABI and bytecode under specific settings. A source file on disk is not automatically the code deployed at an address.

Read the example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract LearningExample {
    uint256 public count;

    function increment() external {
        count += 1;
    }
}

This complete toy contract stores a counter. It has no funds or privileged behavior.

QUICK CHECK · NO PRESSURE

Does a pragma automatically download the required compiler?

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.