Skip to content

Verify with Hardhat

Hardhat has an nyc plugin: Hardhat nyc plugin

Note: Hardhat was previously Buidler.

Install the plugin

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

Configure the plugin in buidler.config.js

  • Add require("@nomiclabs/hardhat-nyc");
  • Add NYBC Chain API key

Warning

keep secret and don’t commit to version control)

Go to register and get API key: https://testnet.nycoin.org/myapikey

  • Set compiler version to match what was deployed
// hardhat.config.js
const { mnemonic, nycApiKey } = require('./secrets.json');

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

  networks: {
    testnet: {
      url: `https://testnet-rpc.nycoin.org`,
      accounts: {mnemonic: mnemonic}
    },
    mainnet: {
      url: `https://nc-dataseed.nycoin.org/`,
      accounts: {mnemonic: mnemonic}
    }
  },

  nyc: {
    // Your API key for nyc
    // Obtain one at https://testnet.nycoin.org/
    apiKey: nycApiKey
  },
  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"
  • Example
$ npx hardhat  verify --network testnet 0xbF39886B4F91F5170934191b0d96Dd277147FBB2
Nothing to compile
Compiling 1 file with 0.5.16
Successfully submitted source code for contract
contracts/NYBC20Token.sol:NYBC20Token at 0xbF39886B4F91F5170934191b0d96Dd277147FBB2
for verification on nyc. Waiting for verification result...

Successfully verified contract NYBC20Token on nyc.
https://testnet.nycoin.org/address/0xbF39886B4F91F5170934191b0d96Dd277147FBB2#code