Solidity

Truffle 部署錯誤:沒有針對其目前網路 ID 的網路配置 (97)

  • May 5, 2021

我在部署與 Truffle 的契約時遇到問題。合約建構子採用文件中的 7 個參數2_deploy_xxx.js。但是,每次我在部署實際合約時都會遇到錯誤。合約需要一個預言機(來自 ChainLink 的 AggregatorV3Interface)。我很困惑,想知道是否有人能幫助我,因為我已經盯著這個太久了。

松露-config.js

const HDWalletProvider = require('truffle-hdwallet-provider');
require('dotenv').config();

const BSC_DEPLOYER_KEY = process.env.BSC_DEPLOYER_KEY;
const BSC_TESTNET_DEPLOYER_KEY = process.env.BSC_TESTNET_DEPLOYER_KEY;

module.exports = {
 networks: {
   development: {
     host: "127.0.0.1",
     port: 8545,
     network_id: "*",
   },
   testnet: {
     provider: () => new HDWalletProvider(BSC_TESTNET_DEPLOYER_KEY, `https://data-seed-prebsc-1-s1.binance.org:8545`, 0, 10),
     network_id: 97,
     confirmations: 10,
     timeoutBlocks: 200,
     skipDryRun: true,
     from: 'address',
   },
   bsc: {
     provider: () => new HDWalletProvider(BSC_DEPLOYER_KEY, `https://bsc-dataseed1.binance.org`),
     network_id: 56,
     confirmations: 10,
     timeoutBlocks: 200,
     skipDryRun: true,
   },
 },
 plugins: [
   'truffle-plugin-verify'
 ],
 api_keys: {
   etherscan: process.env.BSCSCAN_API_KEY
 },
 mocha: {
   // timeout: 100000
 },

 compilers: {
   solc: {
     version: "0.6.12",
     settings: {
       optimizer: {
         enabled: true,
         runs: 999999
       },
     }
   },
 }
}

2_deploy_prediction.js

const BnbPricePrediction = artifacts.require("BnbPricePrediction");
const AggregatorV3Interface = artifacts.require("AggregatorV3Interface");

const ADMIN_ADDRESS = '';
const OPERATOR_ADDRESS = '';
const INTERVAL_BLOCKS = 100;
const BUFFER_BLOCKS = 20;
const MIN_BET_AMOUNT = 1000000000000000;
const ORACLE_UPDATE_ALLOWANCE = 300;

module.exports = function (deployer, network, accounts) {
   console.log(network);

   let adminAddress = ADMIN_ADDRESS;
   let operatorAddress = OPERATOR_ADDRESS;
   let intervalBlocks = INTERVAL_BLOCKS;
   let bufferBlocks = BUFFER_BLOCKS;
   let minBetAmount = MIN_BET_AMOUNT;
   let oracleUpdateAllowance = ORACLE_UPDATE_ALLOWANCE;

   deployer.deploy(AggregatorV3Interface);

   let oracle = AggregatorV3Interface.address

   deployer.deploy(
       BnbPricePrediction,
       oracle,
       adminAddress,
       operatorAddress,
       intervalBlocks,
       bufferBlocks,
       minBetAmount,
       oracleUpdateAllowance
   );
   console.table({
       BnbPricePrediction:BnbPricePrediction.address
   })
};

松露錯誤

2_deploy_prediction.js
======================
testnet

Error: BnbPricePrediction has no network configuration for its current network id (97).
   at Function.network (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/contract/lib/contract/properties.js:108:1)
   at Function.getter (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/contract/lib/contract/constructorMethods.js:282:1)
   at Function.get (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/contract/lib/contract/properties.js:129:1)
   at Function.getter (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/contract/lib/contract/constructorMethods.js:279:1)
   at module.exports (/Users/n0rden/tendie-prediction/migrations/2_deploy_prediction.js:36:47)
   at Migration._load (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:56:1)
   at Migration.run (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:203:1)
   at Object.runMigrations (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
   at Object.runFrom (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
   at Object.runAll (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
   at Object.run (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
   at runMigrations (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:263:1)
   at Object.run (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:228:1)
   at Command.run (/Users/n0rden/.config/yarn/global/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)

我的問題的解決方案是將 AggV3Int 作為必需的工件刪除,分配已部署的 oracle 的地址,並將部署器功能更改為非同步await部署器.deploy。

測試網連結的額外 2 個參數 0 和 10 是什麼?我認為如果您更改提供者: () => new HDWalletProvider(BSC_TESTNET_DEPLOYER_KEY, https://data-seed-prebsc-1-s1.binance.org:8545, 0, 10),

提供者:() => 新 HDWalletProvider(BSC_TESTNET_DEPLOYER_KEY, https://data-seed-prebsc-1-s1.binance.org:8545),

它應該工作。

引用自:https://ethereum.stackexchange.com/questions/98297