You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

2021年11月后BSC testnet获取API密钥及Hardhat合约验证问询

BSC测试网Hardhat合约验证可行方案

核心问题说明

2021年11月后BSC测试网仍支持合约验证,你遇到的问题均为配置误解和参数错误导致:

  • BSC测试网无需单独申请API密钥,直接使用BSC主网申请的有效API密钥即可正常调用验证接口
  • 报错Error in plugin @nomiclabs/hardhat-etherscan: testnet is an invalid address是Hardhat配置文件中网络参数、etherscan配置错误导致

修正配置步骤

  1. 确保已安装最新版@nomiclabs/hardhat-etherscan插件
  2. 修改hardhat.config.js配置,参考示例如下:
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");

module.exports = {
  solidity: "0.8.17", // 替换为你实际使用的solidity版本
  networks: {
    bscTestnet: {
      url: "https://data-seed-prebsc-1-s1.binance.org:8545/",
      chainId: 97,
      accounts: ["你的部署钱包私钥"],
    }
  },
  etherscan: {
    apiKey: {
      bscTestnet: "你在BSC主网申请的API密钥"
    },
    customChains: [
      {
        network: "bscTestnet",
        chainId: 97,
        urls: {
          apiURL: "https://api-testnet.bscscan.com/api",
          browserURL: "https://testnet.bscscan.com"
        }
      }
    ]
  }
};

执行验证命令

配置完成后,使用正确的命令发起验证,注意--network参数后的值要和配置文件中的网络名称完全一致:
npx hardhat verify --network bscTestnet 你的合约部署地址 构造函数入参

常见验证失败补充说明

  • 确保solidity版本、编译优化参数和部署合约时使用的参数完全一致
  • 若合约引用了第三方库,需要在配置中提前声明对应库的部署地址
  • 若构造函数有多个入参,需按部署时的传入顺序依次填写在命令末尾

内容的提问来源于stack exchange,提问作者Cho Chung Hyun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 11:36:03