Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.blockscout.com/llms.txt Use this file to discover all available pages before exploring further.

Verify contracts with the Hardhat plugin

Verify smart contracts on Blockscout from your Hardhat project using the hardhat-verify plugin, on either Hardhat 3 (native Blockscout support, Pro API key optional) or Hardhat 2 (per-instance API).
Hardhat is a full-featured development environment for contract compilation, deployment and verification. The hardhat-verify plugin supports contract verification on Blockscout. The setup differs depending on which major version of Hardhat your project uses, since the plugin’s config format changed between Hardhat 2 and Hardhat 3.
A plain npm install @nomicfoundation/hardhat-verify installs v3, which targets Hardhat 3. If your project is using Hardhat 2, install with the @hh2 tag instead (@nomicfoundation/hardhat-verify@hh2). Check which version applies to you before following the steps below.

Hardhat 3

Hardhat 3’s hardhat-verify plugin (v3.1.0+) has built-in Blockscout support. As of v3.1.0, it also supports an apiKey to use the Blockscout Pro API.
  1. Install Hardhat and the plugin

2) Register the plugin

3) Configure Blockscout (if your instance needs an API key)

Singular Blockscout instances don’t currently require a key. However, if you are using the recommended Pro API setup, add your key under verify.blockscout:
We recommend using a configuration variable (as shown above) rather than hardcoding the key in your config file.
You can disable Blockscout verification entirely by setting enabled: false under verify.blockscout.

4) Verify

Omitting blockscout runs verification against every configured provider (Etherscan, Blockscout, Sourcify); passing it explicitly scopes the run to Blockscout only.

Programmatic verification

verifyContract isn’t re-exported from the Hardhat toolboxes — install the plugin directly and import from @nomicfoundation/hardhat-verify/verify.

Hardhat 2

This is Hardhat 2 syntax — install with @nomicfoundation/hardhat-verify@hh2. This path uses the per-instance API (no key required); it cannot reach the Pro API. If you need Pro API verification, migrate to Hardhat 3 (see above).

1) Install Hardhat

If you are starting from scratch, create an npm project by going to an empty folder, running npm init, and following the instructions. Recommend npm 7 or higher. Once your project is ready: npm instructions
yarn instructions

2) Create a project

Run npx hardhat in your project folder and follow the instructions to create (more info here).

3) Install plugin

Install the hardhat-verify plugin npm
yarn
Note the @hh2 tag above — plain npm install @nomicfoundation/hardhat-verify now installs v3 (Hardhat 3), which uses a different config format entirely (see the Hardhat 3 section above).

4) Add plugin reference to config file

Add the following statement to your hardhat.config.js.
If using TypeScript, add this to your hardhat.config.ts. More info on using typescript with hardhat available here.

Config File and Unsupported Networks

Your basic Hardhat config file (hardhat.config.js or hardhat.config.ts) will be setup to support the network you are working on. In this example we use the Optimism Sepolia test network and a .ts file. Here we add an RPC url without an API key, however some value is still required. You can use any arbitrary string. More info. In order to use Blockscout explorer for the verification, you have to specify the explorer details under a customChains object. It includes:
  • chainId - Network chain ID
  • apiURL - Block explorer API URL
  • browserURL - Block explorer URL
Find an extensive list of ChainIDs at https://chainlist.org/.
Note the network name in customChains must match the network name in the apiKey object.

Verifying on multiple chains?

If you deploy to more than one network, you don’t need a separate config block per chain. Define your chains once in an array and generate networks, etherscan.apiKey, and customChains from it:
Run npx hardhat verify --list-networks at any time to confirm which network identifiers are registered in your config.

Deploy and Verify

For deployment we will use Hardhat Ignition - built-in Hardhat deployment system.

Deploy

Verify

The plugin requires you to include constructor arguments with the verify task and ensures that they correspond to expected ABI signature. However, Blockscout ignores those arguments, so you may specify any values that correspond to the ABI.
Optimism Sepolia example.
If you’re using the multi-chain config, the same command works unchanged for any chain in your CHAINS array — just swap --network optimism-sepolia for --network base, --network arbitrum-one, etc.

Automatically verified contracts

Sometimes the contract may be automatically verified via Ethereum Bytecode Database service. In that case you may see the following response:
In that case, you may try to enforce using --force flag*. It prevents Hardhat from checking if the contract is already verified, and forces it to send a verification request anyway. Notice, that it is helpful only if the contract was automatically verified partially. That way, new verification sources would be saved. If the contract was fully verified already, that just returns an error.

Confirm Verification on BlockScout

Go to your BlockScout instance and paste the contract address into the search bar.
Scroll down to see verified status. A green checkmark ✅ means the contract is verified.
If your screen size is limited, you may need to click the 3 dots to view and click through to the contract.
Scroll down to see and interact with the contract code.

Video example

Community video created by Carlos Rodriguez for the Soneium Minato testnet, but can be applicable to any chain.

FAQ

Although you receive an error, the contracts should be verified during the previous steps and you can ignore. Check in the explorer to make sure the contracts have been verified.
On Hardhat 2 (per-instance route), no, any non-empty string works, and each network still needs its own entry in the apiKey object since the network name in customChains must match a key in apiKey. On Hardhat 3, use a key if your Blockscout instance requires one (e.g. the Pro API); most instances don’t.
Yes, as of @nomicfoundation/[email protected] on Hardhat 3 — pass your key via verify.blockscout.apiKey. This isn’t available on the Hardhat 2 path (@hh2), which only reaches keyless, per-instance Blockscout APIs; migrate to Hardhat 3 if you need Pro API verification through this plugin.

Resources

Learn more about plugin configs, troubleshooting etc. at https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify (Hardhat 2) or https://hardhat.org/docs/plugins/hardhat-verify (Hardhat 3).