我正在尝试从 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
最佳答案
安装最新版本的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'
}
关于solidity - Truffle 合约验证无法在 BSC 测试网上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66062761/