0

I set my infura endpoint and mnemonic to deploy the contract to the Rinkeby testnet. Like this below.

const infuraKey = process.env.INFURA_KEY
const test_mnemonic = process.env.TEST_MNEMONIC

networks: {
  rinkeby: {
    provider: () => new HDWalletProvider(test_mnemonic, `https://rinkeby.infura.io/v3/${infuraKey}`),
    network_id: 4,
    gas: 6900000,
    gasPrice: 10000000000,
    confirmations: 2,
    timeoutBlocks: 200,
    skipDryRun: true
  }
}

My account[0] is 0xeA28Ab53fFF23859c64DB5BAaA64E466713Afae7, but when I try to deploy with this command truffle migrate --network rinkeby, it fails with this error like below.

Error: Error: Error:  *** Deployment Failed ***

"Migrations" could not deploy due to insufficient funds

* Account:  0x9416c8F57eddFeb491F2d728EEb13781662Ac606
* Balance:  0 wei
* Message:  insufficient funds for gas * price + value
* Try:
  + Using an adequately funded account
  + If you are using a local Geth node, verify that your node is synced.

at Object.run (/Users/deleo/.nvm/versions/node/v12.13.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:96:1)
at processTicksAndRejections (internal/process/task_queues.js:93:5)

I've searched that if my mnemonic includes 0x9416c8F57eddFeb491F2d728EEb13781662Ac606, but it didn't. I have no idea why truffle keeps migrating with wrong account.

UPDATE

I've found that at truffle console (truffle console --network rinkeby), I typed web3.eth.getAccounts() and it showed that the first account is 0x9416c8F57eddFeb491F2d728EEb13781662Ac606. Why truffle migrate uses this default account after I set my mnemonic? And where is this default account set from? How could I set my config to use my mnemonic?

0

Please try this way for your config:

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

const providerFactory = network =>
  new HDWalletProvider(
    process.env.MNEMONICS || "", // Mnemonics of the deployer
    `https://${network}.infura.io/v3/${process.env.INFURA_KEY}`, // Provider URL => web3.HttpProvider
    0,
    20
  );

module.exports = {
  compilers: {
    solc: {
      version: "^0.5.5",
      optimizer: {
        enabled: true,
        runs: 200
      },
    }
  },
  networks: {
    rinkeby: {
      provider: providerFactory("rinkeby"),
      network_id: 4,
      gas: 6900000,
      gasPrice: 10000000000 // 10 Gwei
    }
  }
};
  • Thank you for the suggestion, but the result is same. – Jung Chun Nov 14 '19 at 0:47
  • Hey @ALATh I've updated my question that I found something else. Could you see it again? – Jung Chun Nov 14 '19 at 1:01
  • Perfect that you found the solution! – AL ATh Nov 15 '19 at 1:16
0

I've figured it out! truffle-hdwallet-provider module was using it's account[0] from m/44'/1'/0'/0. But I was trying to use the account from m/44'/60'/0'/0 which is by mnemonic creator tool from BIP39. This was the reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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