LinuxCommandLibrary

solc

TLDR

Compile a Solidity file and output bytecode

$ solc --bin [contract.sol]
copy
Compile and output ABI
$ solc --abi [contract.sol]
copy
Compile with optimization enabled
$ solc --optimize --bin [contract.sol]
copy
Output to a directory
$ solc -o [output_dir] --bin --abi [contract.sol]
copy
Compile with Standard JSON input/output
$ solc --standard-json < [input.json]
copy
Show estimated gas for functions
$ solc --gas [contract.sol]
copy
Output abstract syntax tree
$ solc --ast-compact-json [contract.sol]
copy
Remap import paths
$ solc [prefix]=[path] [contract.sol]
copy

SYNOPSIS

solc [options] [input-files]

DESCRIPTION

solc is the command-line compiler for Solidity, the primary programming language for Ethereum smart contracts. It compiles Solidity source code into EVM (Ethereum Virtual Machine) bytecode that can be deployed to Ethereum and compatible blockchains.
The compiler can produce various outputs including bytecode, ABI definitions, assembly, abstract syntax trees, gas estimates, and documentation. The optimizer can reduce bytecode size and gas costs. Standard JSON mode provides structured input/output for integration with build tools.
Import paths can be remapped using the context:prefix=path syntax, allowing flexible project structures. The compiler also supports LSP mode for IDE integration.

PARAMETERS

--bin

Output binary (bytecode) of the contracts.
--abi
Output ABI (Application Binary Interface) specification.
--optimize
Enable bytecode optimizer.
--optimize-runs n
Optimize for n contract invocations (default: 200).
-o, --output-dir path
Output directory for compiled artifacts.
--standard-json
Use Standard JSON input/output mode. Reads from stdin if no file given.
--ast-compact-json
Output AST in compact JSON format.
--asm
Output EVM assembly.
--gas
Output estimated gas usage for functions.
--metadata
Output contract metadata.
--userdoc
Output user documentation (NatSpec).
--devdoc
Output developer documentation (NatSpec).
--combined-json keys
Output combined JSON with specified keys (abi, bin, metadata, etc.).
--base-path path
Base path for imports.
--include-path path
Additional path for imports.
--evm-version version
Target EVM version (homestead, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul, berlin, london, paris, shanghai).
--via-ir
Enable compilation via Yul IR.
--lsp
Run as Language Server Protocol backend.
--version
Display version information.

CAVEATS

Different Solidity versions may have incompatible syntax; use solc-select to manage multiple versions. The optimizer should be tested thoroughly as it can sometimes introduce subtle issues. Gas estimates are approximations and may differ from actual execution costs. EVM version must match the target blockchain's capabilities.

HISTORY

Solidity was proposed by Gavin Wood in 2014 and developed by the Ethereum Foundation's Solidity team. The first release was in 2015 alongside Ethereum's launch. The language and compiler have evolved significantly, with major versions introducing features like ABIEncoderV2, custom errors, and user-defined value types. Development continues actively to improve safety, efficiency, and developer experience.

SEE ALSO

solc-select(1), forge(1), hardhat(1), remix(1)

Copied to clipboard