KCC Documents
  • Quickstart
  • Overview
    • Introduction
    • Features
    • Our Goal
    • Consensus Engine
    • Marketing Guide
      • Requirements
      • KCC Official Website Resource
      • KCC Social Media Promotion
      • PR & Third-Party Marketing Support
  • Developers
    • Network Endpoints
    • Deploy Smart Contract
      • Using Hardhat
      • Using Remix
    • Verify Smart Contract
      • Using Hardhat
      • Using Foundry
      • Using Remix
    • Issue ERC20 Token
    • Deploy NFTs
      • Create A Foundry Project
      • Create Your ERC721 Contract
      • Add Metadata
    • Run a Node
      • Hardware & System Requirements
      • Install KCC
      • Run A Full Node
      • Run A Validator Node
        • Block Rewards
        • Apply For Running A Validator
        • Manager Account And Validator Account
        • Run A Validator
      • Troubleshooting
    • Explorer
    • Oracles
      • KCC Oracle
    • Bridge
    • Dev Toolkit
    • Data
      • Indexing and Querying
        • The Graph
        • Using KCC's hosted subgraph
    • Gas Revenue Program
      • Rules for Calculation of Gas Revenue
      • How to Join the KCC Gas Revenue Program
  • Individuals
    • Wallet
      • Supported Wallet
      • Tutorial on how to set up wallet
      • Mutisig Wallet
        • Create New Safe
        • Send KCS From Your Safe
        • Use A DApp With Your Safe
    • Network Configuration
      • Configure Value
      • Tutorial on how to config KCC network in Metamask
      • Tutorial on how to config KCC network in Chainlist
    • Bridge Assets
      • Bridge assets from others chains
      • KCC Bridge
      • Bridge assets form Exchange
    • Find a dApp
      • Add Your dAPP
    • KCS Token
      • Get KCS
      • Stake KCS
        • How to participate in KCS Staking
        • How to redeem staked KCS
        • How to check or claim staking rewards
  • FAQs
    • FAQs
      • General FAQs
      • KCS and Staking FAQs
      • Validator FAQs
  • Future Developments
    • Milestone
  • CONTACT US
    • Contact Us
  • Disclosure
    • Disclaimers
    • Risk Statement
    • Media Kit
Powered by GitBook
On this page
  • Get Started
  • 1) Install Hardhat
  • 2) Create a project
  • 3) Install plugin
  • 4) Add plugin reference to config file
  • Config File
  • Deploy and Verify
  • Deploy
  • Verify
  • Confirm Verification on KCC Scan
  • Resources
  1. Developers
  2. Verify Smart Contract

Using Hardhat

PreviousVerify Smart ContractNextUsing Foundry

Last updated 1 year ago

is a full-featured development environment for contract compilation, deployment and verification. The supports contract verification on kcc scan.

Get Started

1) Install Hardhat

If you are starting from scratch, create an npm project by going to an empty folder, running npm init, and following the instructions. Recommend npm 7 or higher.

Once your project is ready:

npm instructions

npm install --save-dev hardhat

yarn instructions

yarn add --dev hardhat

pnpm instructions

pnpm add -D hardhat

2) Create a project

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

3) Install plugin

Install the (requires v3.0.0+).

npm

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

yarn

yarn add --dev @nomiclabs/hardhat-etherscan

pnpm

pnpm add -D @nomiclabs/hardhat-etherscan

4) Add plugin reference to config file

Add the following statement to your hardhat.config.js.

require("@nomiclabs/hardhat-etherscan");
import "@nomiclabs/hardhat-etherscan";

Config File

You can add a customChains object to the config file. It includes:

  • chainID - Network chain ID

  • apiURL - Block explorer API URL

  • browserURL - Block explorer URL

require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");
require('hardhat-deploy');

let secret = require("./secret");

module.exports = {
  solidity: "0.8.17",
  networks: {
    kt: {
      url: 'https://rpc-testnet.kcc.network/',
      accounts: [secret.key],
    },
    km: {
      url: 'https://rpc-mainnet.kcc.network/',
      accounts: [secret.key],
    }
  },
  etherscan: {
    apiKey: {
      kt: "abc",
      km: "abc"
    },
    customChains: [
      {
        network: "km",
        chainId: 321,
        urls: {
          apiURL: "https://scan.kcc.io/api",
          browserURL: "https://scan.kcc.io/"
        }
      },
      {
        network: "kt",
        chainId: 322,
        urls: {
          apiURL: "https://scan-testnet.kcc.network/api",
          browserURL: "https://scan-testnet.kcc.network/"
        }
      }
    ]
  }
};

Deploy and Verify

Deploy

npx hardhat run scripts/deploy.js --network kt
Contract deployed to: 0x3F0A49981D3204A8E7bD7871aDEFBC6379A05410

Verify

You can include constructor arguments with the verify task.

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

KCC Testnet example (has constructors).

D:\hardhat>npx hardhat verify --network kt 0x3F0A49981D3204A8E7bD7871aDEFBC6379A05410 "0x0576a174D229E3cFA37253523E645A78A0C91B57,0xae3DB39196012a7bF6D38737192F260cdFE1E7Ec"
Nothing to compile
Compiling 1 file with 0.8.0
Successfully submitted source code for contract
contracts/KCCPaymaster.sol:KCCPaymaster at 0x3F0A49981D3204A8E7bD7871aDEFBC6379A05410
for verification on the block explorer. Waiting for verification result...

Successfully verified contract KCCPaymaster on Etherscan.
https://scan-testnet.kcc.network/address/0x3F0A49981D3204A8E7bD7871aDEFBC6379A05410#code

Note the verify task will not be listed in the available tasks lists at npx hardhat --config but should work as expected.

If not, check you have the minimum required version of the nomiclabs-hardhat-etherscan plugin (v3.0.0+) installed

Confirm Verification on KCC Scan

Go to KCC Scan instance and paste the contract address into the search bar. If verified, the code tab will display a green checkmark.

Selecting the Code tab will provide additional information about your contract.

Resources

If using TypeScript, add this to your hardhat.config.ts. .

Your basic (hardhat.config.js or hardhat.config.ts) will be setup to support the network you are working on. In this example we use the kcc test network and a .js file.

Learn more about plugin configs, troubleshooting etc. at

Hardhat
Hardhat Etherscan plugin
more info here
hardhat-etherscan plugin
More info on using typescript with hardhat available here
Hardhat config file
https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html