1
votes

I am trying to deploy a test contract on Binance Smart Chain network. I am using metamask, and truffle to create and test the contract. My folder structure looks like this

const HDWalletProvider = require('truffle-hdwallet-provider-privkey');
    const privateKeys = process.env.PRIVATE_KEYS || ""
    
    module.exports = {
      networks: {
        development: {
          host: "127.0.0.1",
          port: 7545,
          network_id: "*"
        },
        binancetestnet: {
          provider: function() {
            return new HDWalletProvider(
              privateKeys.split(','), // Array of account private keys
              `https://data-seed-prebsc-1-s1.binance.org:8545/${process.env.INFURA_API_KEY}`// Url to an Ethereum Node
            )
          },
          gas: 5000000,
          gasPrice: 25000000000,
          network_id: 97
        }
      },
    
      // Set default mocha options here, use special reporters etc.
      mocha: {
        // timeout: 100000
      },
    
      // Configure your compilers
      compilers: {
        solc: {
           version: "0.7.3",    // Fetch exact version from solc-bin (default: truffle's version)
          // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
          // settings: {          // See the solidity docs for advice about optimization and evmVersion
          //  optimizer: {
          //    enabled: false,
          //    runs: 200
          //  },
          //  evmVersion: "byzantium"
          // }
        }
      }
    };

Truffle Deployment Error

Macbook-Air Oracle % truffle migrate --reset --network binancetestnet
Error: Cannot find module 'truffle-hdwallet-provider-privkey'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/macbbok/Desktop/Oracle/truffle-config.js:1:26)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at Object.require (internal/modules/cjs/helpers.js:25:18)
    at Function.load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/index.js:161:1)
    at Function.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/index.js:150:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:199:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)
    at Object.module.exports (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/cli.js:56:1)
    at __webpack_require__ (/usr/local/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:19:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:83:1
    at Object.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:89:10)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Truffle v5.1.54 (core: 5.1.54)
Node v10.16.3

I have attached all the code with errors I am facing. Can anyone help me with it? I have also Installed the HD Wallet provider as well. Truffle compile worked successfully.

1
you are missing source code module called truffle-hdwallet-provider-privkey , verify you have the files in the correct directoryNulik
i have installed using npm install @truffle/hdwallet-provider It installed Successfully. But I encountered a new problem while deployingBsc Talk

1 Answers

0
votes

After Installing Truffle HD wallet provider Now Facing

MacBook-Air Test % truffle migrate --reset --network binancetestnet

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

Error: Could not create addresses from your mnemonic or private key(s). Please check that your inputs are correct.
    at new HDWalletProvider (/Users/macbook/Desktop/Test/node_modules/@truffle/hdwallet-provider/src/index.ts:124:13)
    at Object.provider (/Users/macbook/Desktop/Test/truffle-config.js:12:16)
    at Object.getProvider (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:20:1)
    at Object.create (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:13:1)
    at TruffleConfig.get [as provider] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/configDefaults.js:200:1)
    at Object.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:206:1
Truffle v5.1.54 (core: 5.1.54)
Node v14.15.4

My Truffle.js code

const HDWalletProvider = require('@truffle/hdwallet-provider');
const privateKeys = process.env.PRIVATE_KEYS || ""
module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    },
    binancetestnet: {
      provider: function() {
        return new HDWalletProvider(
          privateKeys.split(','), // Array of account private keys
          `https://data-seed-prebsc-1-s1.binance.org:8545/${process.env.INFURA_API_KEY}`// Url to an Ethereum Node
        )
      },
      gas: 5000000,
      gasPrice: 25000000000,
      network_id: 97
    }
  },

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

  // Configure your compilers
  compilers: {
    solc: {
       version: "0.7.3",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  }
};

My .env file

ETHERSCAN_API_KEY=https://data-seed-prebsc-1-s1.binance.org:8545/
INFURA_API_KEY=https://data-seed-prebsc-1-s1.binance.org:8545/
PRIVATE_KEYS="9xxxxx3fb486a57ad13e6db71xxxxx456e4128d51ecxxxxxxxd"
DEV_ADDRESS="0xxxxxxe80e3a43EBCab9A6CeC9d9e2a49100AxxxC"