https://github.com/trufflesuite/truffle-hdwallet-provider/blob/master/README.md provides sample usage for the deployment configuration inside tuffle.js.

I need a sample that update the Web3 currentProvider inside a web page to be used differently with every user (I will use the code upon a user request after generating the mnemonic seed words)


Thanks to @jsantos, and I found it here also: https://gnosis-apollo.readthedocs.io/en/latest/pm-js-usage.html.

Actually, it was not mentioned in the documentation that the truffle-hdwallet-provider is compatible with Web3 and could be passed in the constructor. I created a pull request for that: https://github.com/trufflesuite/truffle/pull/1850. Bellow is the code snippet:

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "mountains supernatural bird..."; // 12 word mnemonic
var provider = new HDWalletProvider(mnemonic, "http://localhost:8545");

// Or, alternatively pass in a zero-based address index.
var provider = new HDWalletProvider(mnemonic, "http://localhost:8545", 5);

// Or, use your own hierarchical derivation path
var provider = new HDWalletProvider(mnemonic, "http://localhost:8545", 5, 1, "m/44'/137'/0'/0/");

// HDWalletProvider is compatible with Web3. Use it at Web3 constructor, just like any other Web3 Provider
const web3 = new Web3(provider); 

// Or, if web3 is alreay initialized, you can call the 'setProvider' on web3, web3.eth, web3.shh and/or web3.bzz

// ...
// Write your code here.
// ...

// At termination, `provider.engine.stop()' should be called to finish the process elegantly.
  • did you try anything yet? post your code. were not going to write it for you.
    – M H
    Commented Nov 17, 2018 at 6:23
  • After many attempts early, where there are limited documentation and errors wear coming in bulk! I used a different library that is: eth-lightwallet to generate seed words for users! Do you like me to delete this question? Or should I keep it for the community? Commented Nov 17, 2018 at 12:11
  • No dont need to delete it.
    – M H
    Commented Nov 18, 2018 at 2:23

1 Answer 1


A solution is provided here. Essentially, you build the HDProvider, just as you would in truffle, and then pass it to Web3.


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.