【问题标题】:Truffle contract verify not working on BSC testnetTruffle 合约验证无法在 BSC 测试网上运行
【发布时间】:2021-05-09 18:21:29
【问题描述】:

我正在尝试从 truffle 验证我已部署的合约,并收到“Etherscan 不支持 ID 为 97 的网络测试网”错误。所以我正在使用 Bscscan,并将我的合同部署在 bsc 测试网上。

我该如何解决这个问题?

我的 truffle-config.js

const HDWalletProvider = require('truffle-hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
const BSCSCANAPIKEY = fs.readFileSync("apikey").toString().trim();

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard BSC port (default: none)
      network_id: "*",       // Any network (default: none)
    },
    testnet: {
      provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-1-s1.binance.org:8545`),
      network_id: 97,
      confirmations: 1,
      timeoutBlocks: 200,
      skipDryRun: true
    },
    bsc: {
      provider: () => new HDWalletProvider(mnemonic, `https://bsc-dataseed1.binance.org`),
      network_id: 56,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.6.12"
    }
  },
  plugins: [
    'truffle-plugin-verify'
  ],
  api_keys: {
    bscscan: BSCSCANAPIKEY
  },
}

结果:

> truffle run verify MyToken@{address}--network testnet
    Etherscan has no support for network testnet with id 97

【问题讨论】:

    标签: solidity smartcontracts truffle binance


    【解决方案1】:

    安装最新版本的truffle-plugin-verify

    现在最新版本是0.5.4。

    npm install truffle-plugin-verify@^0.5.4 -D
    

    为什么会这样? 在这个文件中 (https://github.com/rkalis/truffle-plugin-verify/blob/32ab0f698b1e151849ab463357cded664c5cffa3/constants.js)

    您可以看到最后两个 API_URL(56 和 97)。这是添加到更高版本而不是您安装的。

    const API_URLS = {
      1: 'https://api.etherscan.io/api',
      3: 'https://api-ropsten.etherscan.io/api',
      4: 'https://api-rinkeby.etherscan.io/api',
      5: 'https://api-goerli.etherscan.io/api',
      42: 'https://api-kovan.etherscan.io/api',
      56: 'https://api.bscscan.com/api',
      97: 'https://api-testnet.bscscan.com/api'
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 2017-11-26
      • 2018-09-12
      • 1970-01-01
      • 2022-07-05
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      相关资源
      最近更新 更多