Chains

BNB Smart Chain

Build web3 dApps effortlessly

BNB Beacon Chain

Sunset Complete

BNB ecosystem’s staking & governance layer

DocumentationGitHubFaucetStake BNBBscScanBSCTraceDev ToolsLearn more about FusionDocumentationBeacon Chain ExplorerToken Recovery ToolDocumentationGitHubFaucetBridgeGreenfieldScanDCellarDev ToolsDocumentationGitHubFaucetBridgeopBNBScanDev Tools

Developers


Submit dApps

BNB Smart ChainBNB GreenfieldopBNBBNB HackBNB Incubation Alliance (BIA)Most Valuable Builder Accelerator Program (MVB)BNB Chain GrantsKickstartGas GrantsTVL Incentive ProgramMEME Coins InnovationSee All Programs

Solutions

Tokenization

Get Your Business Into Web3

Company TokenizationReal World Assets TokenizationNFT Loyalty ProgramLaunch MemecoinStep by Step Guide

Ecosystem

Staking

Earn BNB and rewards effortlessly

Native StakingLiquid Staking

Community

Careers🔥

Explore Opportunities on BNB Chain

BNB Chain CareersEcosystem Jobs
Contact UsGet Started
Contact UsGet Started

Verify Smart Contract with Hardhat

2021.2.2  •  1 min read
Blog post image.
Code of honor: This tutorial is based on the post from https://openzeppelin.com/ Thanks for your contributions!

Hardhat has an Etherscan plugin: Hardhat Bscscan plugin

Please read this blog to lean about the fundamentals of Hardhat.

Install the plugin

npm install --save-dev @nomiclabs/hardhat-etherscan

Go to BSCScan and register an API key: https://bscscan.com/myapikey

Configure the plugin in buidler.config.js

  • Add require("@nomiclabs/hardhat-etherscan");
  • Add Bscscan API key
Warning
keep secret and don’t commit to version control
  • Set compiler version to match what was deployed
// hardhat.config.js
const { mnemonic, bscscanApiKey } = require('./secrets.json');

require('@nomiclabs/hardhat-ethers');
require("@nomiclabs/hardhat-etherscan");
/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {

  networks: {
    testnet: {
      url: `https://data-seed-prebsc-1-s1.binance.org:8545`,
      accounts: {mnemonic: mnemonic}
    },
    mainnet: {
      url: `https://bsc-dataseed.binance.org/`,
      accounts: {mnemonic: mnemonic}
    }
  },

  etherscan: {
    // Your API key for Etherscan
    // Obtain one at https://bscscan.com/
    apiKey: bscscanApiKey
  },
  solidity: "0.5.12"
};

Verify

Warning
Remove any unnecessary contracts and clear the artifacts otherwise these will also be part of the verified contract.

Run the following command:

npx buidler verify --network mainnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
$ npx hardhat  verify --network testnet 0xbF39886B4F91F5170934191b0d96Dd277147FBB2
Nothing to compile
Compiling 1 file with 0.5.16
Successfully submitted source code for contract
contracts/BEP20Token.sol:BEP20Token at 0xbF39886B4F91F5170934191b0d96Dd277147FBB2
for verification on Etherscan. Waiting for verification result...

Successfully verified contract BEP20Token on Etherscan.
https://testnet.bscscan.com/address/0xbF39886B4F91F5170934191b0d96Dd277147FBB2#code

Share