How to Verify Smart Contracts on BlockScout with Hardhat
Published: 2024-05-10 11:54:00

Verifying a smart contract on Blockscout makes the contract source code publicly available and verifiable, which creates transparency and trust in the community.

This guide will walk you through verifying a smart contract on [Blockscout](http://blockscout.com) with [Hardhat](https://hardhat.com).

## Prerequisites

Before you begin the steps in this guide, please ensure you have the following:[​](https://docs.celo.org/developer/verify/hardhat#prerequisites)

* You should have a [Hardhat project](https://hardhat.org/hardhat-runner/docs/getting-started#quick-start) initialized on your machine.
    
* An Etherscan Account. Don't have one? go to Etherscan and [sign up](https://etherscan.io) for an account.
    

## Verifying the Smart Contract using Hardhat

### Step 1: Install the `Hardhat-Verify` Plugin

The `hardhat-verify` plugin helps you verify the source code for your Solidity contracts.

In your project directory, install `hardhat-verify`

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

And add the following statement to your `hardhat.config.js`:

```javascript
require("@nomicfoundation/hardhat-verify");
```

Or, if you are using TypeScript, add this to your `hardhat.config.ts`:

```javascript
import "@nomicfoundation/hardhat-verify";
```

### Step 2: Configure Hardhat

Add the following configuration to the `config` object in `hardhat.config.js`.

```javascript
 etherscan: {
    // Your API key for Etherscan
    // Obtain one at https://etherscan.io/
    apiKey: {
      mode: '<ETHERSCAN_API_KEY>',
    },
    customChains: [
      {
        network: 'mode',
        chainId: 919,
        urls: {
          apiURL: 'https://sepolia.explorer.mode.network/api\?',
          browserURL: 'https://sepolia.explorer.mode.network',
        },
      },
    ],
  },
```

Replace `<ETHERSCAN_API_KEY>` with your API key for Etherscan. Under your Etherscan account settings, find the “API Keys” section. Generate one API key using the Free Plan.

This is what the `hardhat.config.js` file looks like:

```javascript
require('@nomicfoundation/hardhat-toolbox');

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: {
    version: '0.8.19',
    settings: {
      evmVersion: 'london',
    },
  },
  networks: {
    'mode': {
      url: 'https://sepolia.mode.network',
      chainId: 919,
      accounts: ['<MY_PRIVATE_KEY>'],
      gasPrice: 10000,
    },
  },
  etherscan: {
    apiKey: {
      mode: '<ETHERSCAN_API_KEY>',
    },
    customChains: [
      {
        network: 'mode',
        chainId: 919,
        urls: {
          apiURL: 'https://sepolia.explorer.mode.network/api\?',
          browserURL: 'https://sepolia.explorer.mode.network',
        },
      },
    ],
  },
};
```

### Step 3: Deploying and Verifying Contracts

**Deploy the Contract**

In your terminal, run the following command:

```javascript
npx hardhat run scripts/deploy.js --network mode
```

> Ensure you have enough funds in your account to pay for Gas. You can grab some test tokens from the [Faucet](https://faucet.modedomains.xyz/) to test your contracts before deploying to the mainnet.

Once your smart contract has been successfully deployed, we can now proceed to verify the contract using the contract address.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707405816947/fbda968f-e802-4e42-aa7b-57b96a8f6039.png align="center")

**Verify the contract**

In your terminal, run the `verify` task, passing the address of the contract, the network where it's deployed, and the constructor arguments that were used to deploy it (if any):

```javascript
npx hardhat verify --network mode DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
```

Where `DEPLOYED_CONTRACT_ADDRESS` is the contract of your deployed smart contract. Also, replace `"Constructor argument 1"` (keep the quotes) with the arguments you passed to your smart contract when deploying.

> If you are using complex constructor arguments, reference the following [Hardhat Documentation.](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#complex-arguments)

### Conclusion

Congratulations! In this guide, we’ve covered how to verify smart contracts on Blockscout with Hardhat using the [`hardhat-verify` plugin](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify) that simplifies the process. Verifying smart contracts is a crucial step in the deployment process because it allows the community to review the source code before usage, thereby promoting transparency and trust within the community.

### What's Next:

Check out these other resources from the Mode C00perators:

* [Mode - Comprehensive Starter Guide](https://mode.hashnode.dev/comprehensive-guide?source=koha)
    
* [How to Get the Developer Role on Mode Discord Server](https://mode.hashnode.dev/get-developer-role?source=koha)
    
* [How to Register a Smart Contract to Mode SFS with Hardhat](https://mode.hashnode.dev/how-to-register-a-smart-contract-to-mode-sfs-with-hardhat?source=koha)