3

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?

3 Answers 3

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
    }
  }
};
3
  • Thank you for the suggestion, but the result is same.
    – Jung Chun
    Commented Nov 14, 2019 at 0:47
  • Hey @ALATh I've updated my question that I found something else. Could you see it again?
    – Jung Chun
    Commented Nov 14, 2019 at 1:01
  • Perfect that you found the solution!
    – AL ATh
    Commented Nov 15, 2019 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.

2
  • could you elaborate? I run into the same problem but I don't understand what are the steps to figure this out Commented Jan 24, 2020 at 21:29
  • @Alessandro Solbiati What I did was send some ETH to address showed on web3.eth.getAccounts(). Commented Mar 27, 2021 at 2:13
0

To get all accounts: truffle develop --network YOUR_NETWORK

You need to collect the mnemonic showed on prompt and put it on truffle-configs in HDWalletProvider settings:

    const ropstenProvider = new HDWalletProvider({
  mnemonic: {phrase: "abc talent waste identify hawk way dolphin crunch maze destroy flock already"},
  providerOrUrl: "wss://ropsten.infura.io/ws/v3/..."});

After this, you're gonna need to add that "weird account" into your Metamask account. For this, copy the FIRST private key and paste on Metamask -> Import Account -> Private Key.

Now, you can go to a faucet and get some coins with your account already setted.

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.