Verify contract
In forge, contracts can be verified at the time of deployment (e.g. usingforge script or forge create), or later if the contracts are already deployed (e.g. using forge verify-contract).
This guide uses the Blockscout PRO API, which covers every Blockscout-supported chain with a single key. Swap the
chain_id value to move between chains, no per-chain setup required. Get a free key at dev.blockscout.com.Tips:
- Specify the
--verifier=blockscoutflag to use the Blockscout verification provider. - Specify
--verifier-url="https://api.blockscout.com/v2/api?chain_id=<chain_id>", swapping<chain_id>for the chain you deployed to (e.g.chain_id=1for Ethereum mainnet,chain_id=8453for Base). See the full list of supported chains at dev.blockscout.com. - Pass your PRO API key with
--etherscan-api-key <your_pro_api_key>. Forge uses this flag name for all Etherscan-compatible verifiers, including Blockscout. - You can specify most configuration options (e.g., evm version, disabling optimizations) via the usual Forge configuration.
Example (Deploy and verify)
Verify a contract with Blockscout right after deployment:Example (Verify already deployed contract)
Verifying against a specific instance
If you’re running a self-hosted Blockscout instance, or verifying on a chain the PRO API doesn’t cover yet, point Forge at that instance’s own API instead. No API key is required for this route./api/ to the end of the Blockscout homepage explorer URL (e.g., --verifier-url=https://eth-sepolia.blockscout.com/api/). The same --verify flag works with forge create and forge script, following the patterns above.
Do I need a real API key?
Do I need a real API key?
For the PRO API, yes. Get a free key at dev.blockscout.com. For the per-instance route, no: any non-empty string works, or you can drop
--etherscan-api-key entirely.Which chains does the PRO API cover?
Which chains does the PRO API cover?
Every Blockscout-indexed mainnet and testnet, under one key. Check the current list at dev.blockscout.com.
Resources
Learn more about Forge’s verification flags at https://www.getfoundry.sh/reference/forge/verify-contract