Skip to content
Logo

Compiler

Configure how Foundry compiles your Solidity contracts, including version management, optimization, and output options.

Solidity version

By default, Foundry auto-detects the required Solidity version from your contracts. To pin a specific version:

foundry.toml
[profile.default]
solc_version = "0.8.28"

Disable auto-detection if you want full control:

foundry.toml
[profile.default]
solc_version = "0.8.28"
auto_detect_solc = false

EVM version

Set the target EVM version for compilation. This affects which opcodes are available:

foundry.toml
[profile.default]
evm_version = "cancun"

Common values: paris, shanghai, cancun, prague (default).

Optimizer settings

Enable the optimizer and configure the number of runs:

foundry.toml
[profile.default]
optimizer = true
optimizer_runs = 200
  • Lower runs (e.g., 1): Optimizes for deployment cost
  • Higher runs (e.g., 1000000): Optimizes for runtime cost (frequent calls)

For production deployments, consider higher optimizer runs:

foundry.toml
[profile.production]
optimizer = true
optimizer_runs = 1000000

Via IR

Enable the new IR-based compilation pipeline for better optimization:

foundry.toml
[profile.default]
via_ir = true

This can produce more optimized bytecode but increases compilation time.

Remappings

Map import paths to actual file locations:

foundry.toml
[profile.default]
remappings = [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@uniswap/=node_modules/@uniswap/",
]

Foundry auto-detects remappings from your lib folder by default. To disable:

foundry.toml
[profile.default]
auto_detect_remappings = false

Ignoring warnings

Suppress specific compiler warnings:

foundry.toml
[profile.default]
ignored_error_codes = ["license", "code-size"]

Or treat all warnings as errors:

foundry.toml
[profile.default]
deny_warnings = true

Bytecode metadata

Control the metadata hash appended to bytecode:

foundry.toml
[profile.default]
bytecode_hash = "none"  # Options: ipfs, bzzr1, none
cbor_metadata = false

Setting bytecode_hash = "none" is useful for deterministic deployments.

Extra output

Include additional compiler output in artifacts:

foundry.toml
[profile.default]
extra_output = ["storageLayout", "metadata"]
extra_output_files = ["ir", "irOptimized"]

Example configuration

A complete compiler configuration for production:

foundry.toml
[profile.default]
solc_version = "0.8.28"
evm_version = "cancun"
optimizer = true
optimizer_runs = 200
via_ir = false
 
[profile.production]
optimizer_runs = 1000000
via_ir = true
bytecode_hash = "none"

For the complete list of compiler options, see the Solidity Compiler Reference.