0

I'm having an issue deploying a contract with Truffle. The contract constructor takes 7 parameters which are all within the 2_deploy_xxx.js file. However, every time I do, I get an error when I get to deploying the actual contract. The contract takes an oracle (AggregatorV3Interface from ChainLink). I'm stumped and wondered if anyone would be able to help me as I've stared at this for too long.

truffle-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
    })
};

Truffle Error

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)
4
  • Kindly show your truffle-config.js file
    – mzaidi
    Commented May 4, 2021 at 19:58
  • @mzaidi just added the truffle-config above
    – architect
    Commented May 4, 2021 at 20:07
  • 2
    I think deployer.deploy is async and you aren't awaiting for it.
    – Ismael
    Commented May 5, 2021 at 2:17
  • 1
    @Ismael that wasn't the completely correct solution but it definitely led me to it. Thank you!
    – architect
    Commented May 5, 2021 at 4:12

2 Answers 2

2

The solution to my issue was removing AggV3Int as a required artifact, assigning the address of an already deployed oracle, and changing the deployer function to be async awaiting deployer.deploy.

1
  • It would be nice if you can add a version of the migration script so they answer is more clear.
    – Ismael
    Commented May 5, 2021 at 5:47
0

What are the extra 2 parameters 0 and 10 with the testnet link? I think if you change provider: () => new HDWalletProvider(BSC_TESTNET_DEPLOYER_KEY, https://data-seed-prebsc-1-s1.binance.org:8545, 0, 10),

to

provider: () => new HDWalletProvider(BSC_TESTNET_DEPLOYER_KEY, https://data-seed-prebsc-1-s1.binance.org:8545),

It should work.

5
  • If i do that I get the following: ``` "Migrations" -- Unknown address - unable to sign transaction for this address: "address". ```
    – architect
    Commented May 4, 2021 at 20:14
  • Just confirming if BSC_DEPLOYER_KEY and BSC_TESTNER_DEPLOYER_KEY are the mnemonics of the address you are using to sign transactions?
    – mzaidi
    Commented May 4, 2021 at 20:18
  • That is correct
    – architect
    Commented May 4, 2021 at 20:19
  • You havent defined this 'address' string anywhere that you have used for the from parameter. If you are using mnemonics from the same address then you dont need to specify from param. Place your actual address in place of the string address
    – mzaidi
    Commented May 4, 2021 at 20:25
  • I removed my actual address. 'address' above is just a placeholder
    – architect
    Commented May 4, 2021 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.