Hardhat Verification Plugin
​Hardhat is a full-featured development environment for contract compilation, deployment and verification. The Hardhat Etherscan plugin supports contract verification on BlockScout.

Get Started

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. Once your project is ready:
npm instructions
1
npm install --save-dev hardhat
Copied!
yarn instructions
1
yarn add --dev hardhat
Copied!

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-etherscan plugin (requires v3.0.0+).
npm
1
npm install --save-dev @nomiclabs/hardhat-etherscan
Copied!
yarn
1
yarn add --dev @nomiclabs/hardhat-etherscan
Copied!

4) Add plugin reference to config file

Add the following statement to your hardhat.config.js.
1
require("@nomiclabs/hardhat-etherscan");
Copied!
If using TypeScript, add this to your hardhat.config.ts. More info on using typescript with hardhat available here.
1
import "@nomiclabs/hardhat-etherscan";
Copied!

Config File

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 Sokol test network and a .js 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.
1
require("@nomiclabs/hardhat-waffle");
2
require("@nomiclabs/hardhat-etherscan");
3
require('hardhat-deploy');
4
​
5
let secret = require("./secret");
6
​
7
module.exports = {
8
solidity: "0.8.0",
9
networks: {
10
sokol: {
11
url: 'https://sokol.poa.network/',
12
accounts: [secret.key],
13
}
14
},
15
etherscan: {
16
// Your API key for Etherscan
17
// Obtain one at https://etherscan.io/
18
apiKey: "abc"
19
}
20
};
Copied!

Deploy and Verify

Deploy

1
D:\hard_hat>npx hardhat run scripts\deploy.js --network sokol
2
Contract deployed to: 0x8595e22825Ba499dB8C77C5c830c235D80f9C0fa
Copied!

Verify

You can include constructor arguments with the verify task.
1
npx hardhat verify --network <network> DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
Copied!
Sokol example (no constructors).
1
D:\hard_hat>npx hardhat verify --network sokol 0x8595e22825Ba499dB8C77C5c830c235D80f9C0fa
2
Nothing to compile
3
Compiling 1 file with 0.8.0
4
Successfully submitted source code for contract
5
contracts/test.sol:Foo at 0x8595e22825Ba499dB8C77C5c830c235D80f9C0fa
6
for verification on Etherscan. Waiting for verification result...
7
​
8
Successfully verified contract Foo on Etherscan.
9
https://blockscout.com/poa/sokol/address/0x8595e22825Ba499dB8C77C5c830c235D80f9C0fa#code
Copied!
Note the verify task will not be listed in the available tasks lists at npx hardhat --config but should work as expected.
If not, check you have the minimum required version of the nomiclabs-hardhat-etherscan plugin (v3.0.0+) installed

Confirm Verification on BlockScout

Go to your BlockScout instance and paste the contract address into the search bar. If verified, the code tab will display a green checkmark.
Selecting the Code tab will provide additional information about your contract.

Resources

Learn more about plugin configs, troubleshooting etc. at https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html​