Verify The Contract

Get Started

Step 1: Create a project

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

Step 2: Config Custom Networks

Your basic Hardhat config file (hardhat.config.js or hardhat.config.ts) will be setup to support BitEigen Testnet.

You have to specify the explorer details under a customChains object. It includes:

import "@nomicfoundation/hardhat-toolbox";
import "dotenv/config";
import { HardhatUserConfig } from "hardhat/config";
import "./tasks/verifySC"

const privateKey = process.env.PRIVATE_KEY;
if (!privateKey) {
  throw new Error("private key not found");
}

const config: HardhatUserConfig = {
  solidity: "0.8.24",
  networks: {
    biteigenTestnet: {
      url: "https://rpc-testnet.biteigen.xyz",
      chainId: 1022,
      accounts: [`0x${privateKey}`]
    },
  },
  etherscan: {
    apiKey: {
      biteigen: "apikey",
    },
    customChains: [
      {
        network: "biteigenTestnet",
        chainId: 1022,
        urls: {
          apiURL: "https://explorer-testnet.biteigen.xyz/api",
          browserURL: "https://explorer-testnet.biteigen.xyz/",
        }
      }
    ],
  },
};

export default config;

Step 3: Deploy and Verify

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

  • Deploy

❯ npx hardhat deploySC --network biteigenTestnet
Counter contract deployed to 
https://https://explorer-testnet.biteigen.xyz/address/0xCF79A6a817F49cE37e7AE73F49A1A5a90FC28c84
  • Verify

Create a new file in the tasks folder verifySC.ts: touch tasks/verifySC.ts.

Add the code below to the verifySC.ts file:

import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";

/**
  * usage: npx hardhat verifySC --addr 0xCF79A6a817F49cE37e7AE73F49A1A5a90FC28c84 --network biteigenTestnet
  */

async function verifySC(taskArgs: {addr: string}, hre: HardhatRuntimeEnvironment) {
  await hre.run("verify:verify", {
    address: taskArgs.addr, // address of the contract needs to be verified.
    construtorArgsParams: [],
  });
}

task('verifySC', 'verify Counter contract')
  .addParam('addr', 'contract address')
  .setAction(verifySC);

Now run the task:

npx hardhat verifySC --addr 0xCF79A6a817F49cE37e7AE73F49A1A5a90FC28c84 --network biteigenTestnet

​Here’s an output example:

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

Successfully verified contract Counter on the block explorer.
https://explorer-testnet.biteigen.xyz/address/0xCF79A6a817F49cE37e7AE73F49A1A5a90FC28c84#code

Automatically verified contracts

Sometimes the contract may be automatically verified via Ethereum Bytecode Database service. In that case you may see the following response:

The contract 0xCF79A6a817F49cE37e7AE73F49A1A5a90FC28c84 has already been verified on Etherscan.
https://explorer-testnet.biteigen.xyz/address/0xCF79A6a817F49cE37e7AE73F49A1A5a90FC28c84?tab=contract

In that case, you may try to enforce using --force flag*.

It prevents Hardhat to check if the contract is already verified, and force it to send verification request anyway. Notice, that it is helpful only if the contract was automatically verified partially. That way, a new verification sources would be saved. If the contract was fully verified already, that just returns an error.

npx hardhat verifySC --addr 0xCF79A6a817F49cE37e7AE73F49A1A5a90FC28c84 --network biteigenTestnet --force

Confirm Verification on BitEigen Explorer

Go to BitEigen Explorer and paste the contract address into the search bar.

Scroll down to see verified status. A green checkmark ✅ means the contract is verified.

Full Source Code

You can find the full source code on GitHub: Full Source Code on GitHub.

Last updated