API Reference

How to Verify a Smart Contract

How to Verify a Smart Contract Using the hardhat-verify Plugin

Prerequisites

Before getting started, you'll need the following:

  • Node.js and npm installed
  • Hardhat installed
  • A l2scan API

Step-by-Step Guide

1. Install the hardhat-verify Plugin

Run the following command in the command line to install the hardhat-verify plugin:

npm install --save-dev @nomicfoundation/hardhat-verify

2. Configure the hardhat-verify Plugin

Add the following code to your Hardhat configuration file (usually hardhat.config.js) to configure the hardhat-verify plugin:

require('nomicfoundation/hardhat-verify');

module.exports = {
  // ...
  etherscan: {
  apiKey: {
      mynetwork: "no-api-key-needed"
    },
  customEndpoints: {
    scrollTestnet: {
      name: "mynetwork",
      chainId: 11111,
      url: "https://{explorer-endpoint}/api",
      explorer: "https://{explorer-endpoint}/",
    },
  },
},

  // ...
};

3. Compile Your Smart Contract

Compile your smart contract using Hardhat by running the following command:

npx hardhat compile

4. Deploy Your Smart Contract

Deploy your smart contract using Hardhat as you normally would.

5. Verify Your Smart Contract

Run the following command to verify your smart contract:

npx hardhat verify --network NETWORK_NAME CONTRACT_ADDRESS "Constructor argument 1" "Constructor argument 2" ...

Replace NETWORK_NAME with the name of the network you deployed your contract to (e.g. scrollTestnet, linea, etc.). Replace CONTRACT_ADDRESS with the address of your deployed contract. If your contract has constructor arguments, include them after the contract address.

6. Check Your Verification Status

After running the verification command, you will receive a verification request ID. You can use this ID to check the status of your verification on l2scan.

Congratulations! You have successfully verified your smart contract using the hardhat-verify plugin.