Skip to main content

Use Hardhat to Verify Smart Contracts

To verify your contracts using Hardhat, you'll need an Etherscan API key and custom network configuration in your hardhat.config.ts file.

It is assumed that you have already completed the deployment of the contract, if not, you can review the tutorials before to complete the contract deployment.

Configure

  1. Add your Mantlescan API key to the .env file.

    ...

    API_KEY=xxx
  2. Modify the hardhat.config.ts configuration to include customChains before moving forward.

    import {HardhatUserConfig} from 'hardhat/config';
    import '@nomicfoundation/hardhat-toolbox';
    import * as dotenv from 'dotenv';

    dotenv.config();

    const config: HardhatUserConfig = {
    solidity: '0.8.19', // solidity version
    defaultNetwork: 'mantleSepolia', // chosen by default when network isn't specified while running Hardhat
    networks: {
    mantle: {
    url: 'https://rpc.mantle.xyz', //mainnet
    accounts: [process.env.ACCOUNT_PRIVATE_KEY ?? ''],
    },
    mantleSepolia: {
    url: 'https://rpc.sepolia.mantle.xyz', // Sepolia Testnet
    accounts: [process.env.ACCOUNT_PRIVATE_KEY ?? ''],
    gasPrice: 20000000,
    },
    },
    etherscan: {
    apiKey: process.env.API_KEY,
    customChains: [
    {
    network: 'mantle',
    chainId: 5000,
    urls: {
    apiURL: 'https://api.mantlescan.xyz/api',
    browserURL: 'https://mantlescan.xyz',
    },
    },
    {
    network: 'mantleSepolia',
    chainId: 5003,
    urls: {
    apiURL: 'https://api-sepolia.mantlescan.xyz/api',
    browserURL: 'https://sepolia.mantlescan.xyz/',
    },
    },
    ],
    },
    };
    export default config;

Verify your contracts

Run the following command to verify the contract located in the "contracts" directory:

npx hardhat verify --network <network> DEPLOYED_CONTRACT_ADDRESS "Constructor arguments"

Sample Outputs

Successfully submitted source code for contract
contracts/Lock.sol:Lock at 0x76B6a0F36CC71d49792eC1740892E8bc9AA7814c
for verification on the block explorer. Waiting for verification result...

Successfully verified contract Lock on the block explorer.
https://sepolia.mantlescan.xyz/address/0x76B6a0F36CC71d49792eC1740892E8bc9AA7814c#code

Now you can head over to Mantle blockchain explorer to check the contract status.