forge verify-contract
NAME
forge-verify-contract - Verify smart contracts on a chosen verification provider.
SYNOPSIS
forge verify-contract [options] address contract
DESCRIPTION
Verifies a smart contract on a chosen verification provider.
You must provide:
- The contract address
- The contract name or the path to the contract (read below) In case of Etherscan verification, you must also provide:
- 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.
You can specify ABI-encoded constructor arguments with --constructor-args. Alternatively,
you can specify a file containing space-separated constructor arguments with --constructor-args-path.
(Note that cache must be enabled in the config for the latter to work.)
OPTIONS
Verify Contract Options
--verifier name
The verification provider. Available options: etherscan, sourcify & blockscout. Default: etherscan.
--verifier-url url
The optional verifier url for submitting the verification request.
Environment: VERIFIER_URL
--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 where x and
y are major and minor version numbers respectively, then search for the 8 hex digits in the version string here.
--num-of-optimizations num
--optimizer-runs num
The number of optimization runs used to build the smart contract.
--constructor-args args
The ABI-encoded constructor arguments. Conflicts with --constructor-args-path.
--constructor-args-path file
The path to a file containing the constructor arguments. Conflicts with --constructor-args.
--chain-id chain
--chain chain
The ID or name of the chain the contract is deployed to.
Default: mainnet
--flatten
Flag indicating whether to flatten the source code before verifying.
If this flag is not provided, the JSON standard input will be used instead.
-f
--force
Do not compile the flattened smart contract before verifying.
--delay delay
Optional timeout to apply in between attempts in seconds. Defaults to 3.
--retries retries
Number of attempts for retrying. Defaults to 15.
--watch
Wait for verification result after submission.
Automatically runs forge verify-check until the verification either fails or succeeds.
Project Options
--build-info
Generate build info files.
--build-info-path path
Output path to directory that build info files will be written to.
--root path
The project's root path. By default, this is the root directory of the current git repository, or the current working directory.
-C path
--contracts path
The contracts source directory.
Environment: DAPP_SRC
--lib-paths path
The path to the library folder.
-R remappings
--remappings remappings
The project's remappings.
The parameter is a comma-separated list of remappings in the format <source>=<dest>.
--cache-path path
The path to the compiler cache.
--config-path file
Path to the config file.
--hh
--hardhat
This is a convenience flag, and is the same as passing --contracts contracts --lib-paths node-modules.
Common Options
-h
--help
Prints help information.
EXAMPLES
-
Verify a contract with JSON standard input on Etherscan
forge verify-contract <address> SomeContract --watch -
Verify a contract on a custom Sourcify instance
forge verify-contract --verifier sourcify \ --verifier-url http://localhost:5000 <address> SomeContract -
Verify a flattened contract built with solc v0.8.11+commit.d7f03943:
forge verify-contract --flatten --watch --compiler-version "v0.8.11+commit.d7f03943" \ --constructor-args $(cast abi-encode "constructor(string,string,uint256,uint256)" "ForgeUSD" "FUSD" 18 1000000000000000000000) \ <address> MyToken -
Verify a flattened contract by specifying constructor arguments in a file:
forge verify-contract --flatten --watch --compiler-version "v0.8.11+commit.d7f03943" \ --constructor-args-path constructor-args.txt <address> src/Token.sol:MyTokenwhere
constructor-args.txtcontains the following content:ForgeUSD FUSD 18 1000000000000000000000