forge-verify-contract - Verify smart contracts on a chosen verification provider.
forge verify-contract
[options] address contract
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.)
{{#include ../common/verifier-options.md}}
--skip-is-verified-check
Send the verification request even if the contract is already verified.
--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.
{{#include ../common/retry-options.md}}
--show-standard-json-input
Command outputs JSON suitable for saving to a file and uploading to block explorers for verification.
--watch
Wait for verification result after submission.
Automatically runs forge verify-check
until the verification either fails or succeeds.
--via-ir
Set viaIR
to true.
If you compiled using --via-ir
when deploying, pass it here too in order to prevent a bytecode mismatch.
{{#include project-options.md}}
{{#include common-options.md}}
-
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:MyToken
where
constructor-args.txt
contains the following content:ForgeUSD FUSD 18 1000000000000000000000
-
Verify a contract with Blockscout right after deployment (make sure you add "/api?" to the end of the Blockscout homepage explorer URL):
forge create --rpc-url <rpc_https_endpoint> --private-key $devTestnetPrivateKey src/Contract.sol:SimpleStorage --verify --verifier blockscout --verifier-url <blockscout_homepage_explorer_url>/api?
-
verify a contract with Oklink
forge verify-contract 0x8CDDE82cFB4555D6ca21B5b28F97630265DA94c4 Counter --verifier oklink --verifier-url https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER --api-key $OKLINK_API_KEY
-
verify a contract with Oklink while deploying
forge create Counter --rpc-url <rpc_https_endpoint> --verify --verifier oklink --verifier-url https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER --etherscan-api-key $OKLINK_API_KEY --private-key $PRIVATE_KEY --legacy