forge verify-contract

NAME

forge-verify-contract - Verify smart contracts on Etherscan.

SYNOPSIS

forge verify-contract [options] --compiler-version compiler_version address contract [etherscan_key]

DESCRIPTION

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.

OPTIONS

Verify Contract Options

--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
    The number of optimization runs used to build the smart contract.

--constructor-args args...
    The ABI-encoded constructor arguments.

--chain-id chain_id
    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.

--delay delay
    Optional timeout to apply in between attempts in seconds.

--retries retries
    Number of attempts for retrying. Defaults to 1.

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

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

SEE ALSO

forge, forge create, forge flatten, forge verify-check