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

Pragma directives and compiler versions

A source constraint and the compiler actually used are different pieces of evidence.

LET’S PICTURE IT

A recipe can require an oven in a temperature range while the cook still chooses and configures the actual oven.

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.

Read the version expression

A pragma such as ^0.8.20 permits compatible compiler versions according to Solidity’s version-constraint rules. It is not the same as pinning one exact compiler binary.

Settings affect output

Optimizer configuration, EVM target and other build settings can change generated bytecode. Reproducibility requires retaining the actual toolchain and settings, not only the pragma line.

Language behavior evolves

Compiler fixes and features can affect accepted source and output. Production code should be tested with the chosen version and target rather than assuming every permitted version is identical.

Verification needs build context

When comparing deployed code with source, use the actual compilation inputs. A matching project name and familiar syntax are weaker evidence than a documented reproducible build.

Read the example

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

contract LearningExample {
    function answer() external pure returns (uint256) {
        return 42;
    }
}

The pragma is a constraint. The verification script records the actual compiler version used.

QUICK CHECK · NO PRESSURE

Does ^0.8.20 necessarily pin exactly compiler 0.8.20?

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.