trufflesuite / truffle-hdwallet-provider

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

Using privateKey not return correct address #77

Closed Mizumaki closed 5 years ago

Mizumaki commented 5 years ago

I want to use private key to access my address, and I tried but It always return the address which is not mine.

var HDWalletProvider = require("truffle-hdwallet-provider");
var privateKey = process.env.KEY;
var infuraApiKey = process.env.INFURA;

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  networks: {
    mainnet: {
      provider: function () {
        return new HDWalletProvider(
          privateKey,
          "https://mainnet.infura.io/v3/" + infuraApiKey
        );
      },
      network_id: 1,
      gas: 2000000,
      gasPrice: 8000000000 // 8 Gwei
    }
  }
};

The "KEY" is definitely correct, because I can access my address through MyEtherWallet using this pricateKEY. And also I'm so sure that this KEY is pure nondecrypted strings which consists 64 characters.

I'm stuck two days, but I can get no answer. I think this code is correct, so I can't find out what is the cause. Thanks in advance...

rwehao commented 5 years ago

check the version of truffle-hdwallet-provider you use. Try the version "^1.0.0-web3one.1".

Mizumaki commented 5 years ago

Wow, thanks!!!!! It works fine and I can correctly access my account. I really appreciate it.