forge-verify-contract - Verify smart contracts on Etherscan.
forge verify-contract
[options] --compiler-version
compiler_version address contract [etherscan_key]
Verifies a smart contract on Etherscan.
You must provide:
- The compiler version used to build your smart contracts (
--compiler-version
, read below) - The contract address
- The path to the contract (read below)
- Your Etherscan API key, either by passing it as an argument or setting
ETHERSCAN_API_KEY
To find the exact compiler version, run ~/.svm/x.y.z/solc-x.y.z --version
and search for the 8 hex digits in the version string here.
The path to the contract is in the format <path>:<contract>
, e.g. src/Contract.sol:Contract
.
By default, smart contracts are verified in a multi-file fashion. If you want to flatten the contract before verifying, pass --flatten
.
This command will try to compile the source code of the flattened contract if --flatten
is passed before verifying. If you do not want that, pass --force
.
--compiler-version
version
The compiler version used to build the smart contract.
To find the exact compiler version, run ~/.svm/x.y.z/solc-x.y.z --version
and search for the 8 hex digits in the version string here.
--num-of-optimizations
num
The number of optimization runs used to build the smart contract.
--constructor-args
args...
The ABI-encoded constructor arguments.
--chain
chain
The chain ID the contract is deployed to (either a number or a chain name).
Default: mainnet
--flatten
Flatten the source code before verifying.
-f
--force
Do not compile the flattened smart contract before verifying.
{{#include project-options.md}}
{{#include common-options.md}}
- Verify a contract built with solc v0.8.11+commit.d7f03943:
forge verify-contract --compiler-version "v0.8.11+commit.d7f03943" \ 0x.. src/Token.sol:MyToken