B² Network
  • B² Network
    • Overview
  • Airdrop Guide
  • Zero-Knowledge Proof Verification Commitment for ZK-Rollup on Bitcoin
  • Tech Architecture
    • Rollup Layer
    • DA Layer
      • Decentralized Storage
      • B² Nodes
      • B² Inscription
      • B² Commitment
      • Bitcoin Network
  • For Users
    • Connecting to B² Mainnet
    • Set Gas Price
    • Join B² Network Discovery
    • Bridge to B² Mainnet
    • Transfer BlockHeadz NFT
    • Add B2 token on BNB Chain
  • For Developers
    • Basic information
    • Write a contract
    • Deploy a contract with Hardhat
    • Verify contract code with Hardhat in Explorer
    • Verify contract code with Hardhat in Blockscout
    • Integrate Particle Account Abstraction
    • Integrate Oracle Services
    • Deploy a rollup node
    • Deploy a rollup archive node
  • Tokenomics
  • Press-Kit
Powered by GitBook
On this page
  • Verify a Smart Contract with hardhat
  • Step-by-Step Guide
  • 1. Install the hardhat-verify Plugin
  • 2. Configure the hardhat-verify Plugin
  • 3. Compile Your Smart Contract
  • 4. Deploy Your Smart Contract
  • 5. Verify Your Smart Contract
  • 6. Check Your Verification Status
  1. For Developers

Verify contract code with Hardhat in Explorer

PreviousDeploy a contract with HardhatNextVerify contract code with Hardhat in Blockscout

Last updated 11 months ago

Verify a Smart Contract with hardhat

This section is a guide on how to verify a smart contract on the B² Network using . Hardhat is a popular smart contract development frameworks. It is used in the B² rollup as a default for deploying and automatically verifying smart contracts.

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

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

module.exports = {
  // ...
  networks: {
    B2Mainnet: {
      url: 'https://rpc.bsquared.network',
      chainId: 223,
      accounts: {
        "your_private_key",
      },
    },
  },
  etherscan: {
    apiKey: {
      B2Mainnet: "no-api-key-needed"
    },
    customChains: [
       {
        network: "B2Mainnet",
        chainId: 223,
        urls: {
          apiURL: "https://explorer.bsquared.network/api",
          browserURL: "https://explorer.bsquared.network/"
        }
       },
    ]
  },
  // ...
};

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 B2Mainnet CONTRACT_ADDRESS "Constructor argument 1" "Constructor argument 2" ...

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 the block explorer.

Hardhat