Skip to content

@contracts:solidity

Compile Solidity source (inline text or a http/ipfs URL) and return the creation bytecode, ready for deploy. Options: version:<x.y.z>, runs:, optimizer:false, via-ir:true, evm:, contract:, libraries:[[Name 0x…]].

⚗️ Experimental — available at next.evmcrispr.com.

Returns: bytes

@contracts:solidity(source version:<value> runs:<value> optimizer:<value> via-ir:<value> evm:<value> contract:<value> libraries:<value>)
NameTypeDescription
sourcestringSolidity source code, or a URL to fetch it from
version:stringCompiler release, e.g. version:0.8.26 (default: from the pragma)
runs:numberOptimizer runs, e.g. runs:1000 (default: 200)
optimizer:booloptimizer:false disables the optimizer
via-ir:boolvia-ir:true compiles through the IR pipeline
evm:stringEVM version, e.g. evm:cancun
contract:stringTarget contract name when the source defines several
libraries:anyDeployed library addresses to link, as an entries array: libraries:[[LibName 0x…] …] — needed when the source's libraries have external functions
# Compile and deploy an inline contract
set $src <<<SOL
pragma solidity 0.8.26;
contract Counter {
uint256 public n;
function inc() public { n++; }
}
SOL
contracts:deploy $counter @contracts:solidity($src)
# Compile a contract hosted at a URL with custom compiler options
set $url 'https://sources.example.com/Counter.sol'
contracts:deploy $counter @contracts:solidity($url runs:1000 via-ir:true)

Options are passed as named arguments, in any order:

OptionEffectDefault
version:0.8.26Pin a compiler releaseNewest release satisfying the root file's pragma solidity
runs:1000Optimizer runs (implies the optimizer is enabled)200
optimizer:falseDisable the optimizerOptimizer enabled
via-ir:trueCompile through the Yul IR pipeline (settings.viaIR)Off
evm:cancunTarget EVM version (settings.evmVersion)Compiler default
contract:MyTokenPick the target contract when several are deployableAuto: single deployable contract in the root file, else root file-name match

Unknown option names throw, so typos never silently change compiler settings. The oldest supported release is 0.6.0.

Imports are prefetched transitively before compiling:

  • Absolute URLs (import "https://…/Lib.sol";) are fetched as written.
  • Relative imports work when the importing file lives at a URL (resolved against it). In inline source they throw — flatten the contract or host it.
  • npm-style imports must pin an exact package version inside the import path (import "@openzeppelin/contracts@5.4.0/token/ERC20/ERC20.sol";). The package tarball is downloaded from the npm registry and verified against its published integrity hash before any file is used — which is why unpinned or ranged paths throw (mutable content has no stable hash to verify).

Compiler builds are verified too: each downloaded soljson release is checked against a hash pinned in the EVMcrispr repo before it is instantiated.

The four @solidity helpers share one compile cache, so a deploy + verify script compiles once. Repeat the same options in every call — different options are a different compile. verify needs a VITE_ETHERSCAN_API_KEY, so the full pipeline is not runnable as a doc example:

load contracts
set $url 'https://raw.githubusercontent.com/me/repo/main/Token.sol'
contracts:deploy $token @contracts:solidity($url runs:1000)
contracts:verify $token --source @contracts:solidity.standardJson($url runs:1000) --contract-name @contracts:solidity.contract($url runs:1000) --compiler @contracts:solidity.compiler($url runs:1000)

The compiler itself (~9 MB) is downloaded from binaries.soliditylang.org on first use and cached for the session.