Skill 2.3.2

Select compiler versions, optimizer settings and EVM targets

Key Concepts

The version pragma limits which compilers may be used, and the tool configuration chooses the exact version, for example solidity: { version: "0.8.34" } in a Hardhat configuration. Using a fixed recent version gives reproducible builds; breaking changes happen only at minor versions such as 0.8 to 0.9.

The optimizer simplifies the bytecode to reduce gas. Its runs parameter estimates how often each part of the code will execute over the contract's life: a low value such as 1 minimises deployment size and cost, and a high value such as 10,000 makes the code larger but cheaper to call. The viaIR setting compiles through the Yul intermediate representation, which can optimise further.

The evmVersion setting selects the hard fork whose opcodes the compiler may use. Recent compilers default to Osaka, the EVM of the Fusaka upgrade. Code compiled for a newer EVM than a chain supports can fail, so developers targeting other EVM chains sometimes select an older version.