3

I was trying to deploy my contract to Binance Smart Chain Testnet and I got this error. I am using truffle and also successfully installed truffle HD wallet Provider.

Truffle Error:-

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 Config.js File

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="94916xxxxxx57ad13e6db71ed9fe5f94456e4128d51xxxxxxxf95xxd"
DEV_ADDRESS="0xbxxxxx80e3a43EBCab9A6CeC9d9e2a491xxxxxxC"

I have attached all the code with errors I am facing. Can anyone help me with it?. Truffle compile worked successfully.

Bsc Talk
  • 41
  • 3

3 Answers3

1

I had the same problem, in my case I simply forgot to add

require("dotenv").config();
zozzancs
  • 154
  • 8
0

I faced a similar problem, and found the solution to use private key instead of mnemonic:

in your .env :

API_URL = "https://ropsten.infura.io/v3/your project id" # note: put your node url here
PRIVATE_KEY = "your account private key"

and in your truffle-config.js:

module.exports= {
....
rospten: {
  provider: () => new HDWalletProvider(
    process.env.PRIVATE_KEY,
    process.env.API_URL), 
    network_id: 3,
    gas: 1000000,
    gasPrice: 20000000000,
    confirmations: 2,
    timeoutBlocks: 200000,
 }
....
}
bghad1
  • 89
  • 8
0

Might be the way you're defining your private key.

Instead of a mnemonic, you can alternatively provide a private key or array of private keys as the first parameter. When providing an array, address_index and num_addresses are fully supported.

var HDWalletProvider = require("truffle-hdwallet-provider");
//load single private key as string
var provider = new HDWalletProvider("3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", "http://localhost:8545");

// Or, pass an array of private keys, and optionally use a certain subset of addresses
var privateKeys = [
  "3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
  "9549f39decea7b7504e15572b2c6a72766df0281cea22bd1a3bc87166b1ca290",
];
var provider = new HDWalletProvider(privateKeys, "http://localhost:8545", 0, 2); //start at address_index 0 and load both addresses
Zi Hang
  • 26
  • 5