← 返回命令列表

Linux command

solc 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Compile a Solidity file

solc --bin [contract.sol]

Compile and output ABI

solc --abi [contract.sol]

Compile with optimization

solc --optimize --bin [contract.sol]

Output to a directory

solc -o [output_dir] --bin --abi [contract.sol]

Compile with Standard JSON

solc --standard-json < [input.json]

Show estimated gas

solc --gas [contract.sol]

Output abstract syntax tree

solc --ast-compact-json [contract.sol]

Remap import paths

solc [prefix]=[path] [contract.sol]

说明

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.

参数

--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.

FAQ

What is the solc command used for?

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.

How do I run a basic solc example?

Run `solc --bin [contract.sol]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --bin do in solc?

Output binary (bytecode) of the contracts.