2022-10-17Web300
请注意,本文编写于 607 天前,最后修改于 607 天前,其中某些信息可能已经过时。

使用hardhat-etherscan

链接地址:https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan

This plugin helps you verify the source code for your Solidity contracts on Etherscan

安装依赖

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

修改hardhat.config.js

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

const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY

etherscan: {
    apiKey: ETHERSCAN_API_KEY,
},

获取etherscan的api key

地址: https://etherscan.io/

注册后进入 https://etherscan.io/myapikey 获取

修改.env

ETHERSCAN_API_KEY=WS6UZK83YCB1GI12236DB1DIDMN7BBVEZF2

tasks

image.png

部署代码

const verify = async (contractAddress, args) => {
  console.log("Verifying contract...");
  try {
    await run("verify:verify", {
      address: contractAddress,
      constructorArguments: args,
    });
  } catch (e) {
    if (e.message.toLowerCase().includes("already verified")) {
      console.log("Already Verified!");
    } else {
      console.log(e);
    }
  }
};

本文作者:前端小毛

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!