trufflesuite / truffle-hdwallet-provider

HD Wallet-enabled Web3 provider
MIT License
400 stars 167 forks source link

account that has funds is found not to #36

Open dkent600 opened 6 years ago

dkent600 commented 6 years ago

I am trying to run truffle migrate against Kovan with the truffle.js configuration shown below. However the migration fails as follows:

Running migration: 1_initial_migration.js Deploying Migrations... Error encountered, bailing. Network state unknown. Review successful transactions manually. Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 454376000000000000 and got: 0.

This in spite of the fact that the account identified by the mnemonic has plenty of KETH in it.

If it matters, the mnemonic was created by Parity.

Doesn't matter what underlying provider I use, Infura or Parity, I get the same result.

I am using truffle-hdwallet-provider@0.0.5.

Any ideas what could be going wrong here?

Thanks

Truffle.js:

const HDWalletProvider = require("truffle-hdwallet-provider");

module.exports = {
  networks: {
    kovan: {
      provider: function () {
        return new HDWalletProvider(mnemonic, providerUrl);
      }
    }
 }
dkent600 commented 6 years ago

calling getAddress() on the hd provider returns the wrong address.

dkent600 commented 6 years ago

Turns out not all mnemonics are created the same, which is surprising to me. I went to https://iancoleman.io/bip39 and created a new mnemonic and it works fine.

Should this be documented somehow? Or maybe it is and I missed something? Or is this a bug?

levino commented 6 years ago

Same problem here. I tried to use the mnemonic generated from ganache cli. Does not work. It would also be helpful if the hd provider would log out the address that it expects to have some funds. I have been debugging this in the dark for a while.

rmi7 commented 6 years ago

same here, even when using https://iancoleman.io/bip39 to create a mnemonic....

rmi7 commented 6 years ago

Think I've uncovered what's happening (at least for my case of this problem),

What's happening

  1. opened my HD wallet using MyCrypto (connected to Ropsten) by entering the Mnemonic, default selected HD path for Derived addresses is: m/44'/1'/0'/0 "Testnet (ETH)"
  2. used a faucet to add Ropsten ETH to address zero I saw in step 1.
  3. ran truffle migrate --network ropsten --dry-run, and console logged the HDWalletProvider getAddress(), I notice it's different than the one I saw in step 1.
  4. went back to MyCrypto and re-entered my mnemonic to start opening my HD Wallet
  5. isntead of just picking the default HD path, I checked the other HD paths from the dropdown, since I am connected to Ropsten it's default set to the one from step 1, but selecting a different one: HD path m/44'/60'/0'/0 "Default (ETH)", I can now see that address zero matches the one I saw in step 3.

Conclusion

truffle-hdwallet-provider uses the HD path m/44'/60'/0'/0 even though we're migrating on a test net.

Short-term Solution

always use Derived addresses at m/44'/60'/0'/0 when opening the HD wallet in MyCrypto or any other wallet, since that is the HD path which is used/opened by truffle-hdwallet-provider.

Long-term solution

Make it possible to configure which HD path truffle-hdwallet-provider uses/opens.