5

I would expect this to return 10 accounts but I get only 1.

const provider = new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/ll2k3jdlKDl")
    web3 = new Web3(provider)
    Promise.promisifyAll(web3.eth)
    let accounts = await web3.eth.getAccountsAsync()

Can anyone explain why? or how I can get more accounts on there. My understanding is that the other 9 accounts should be derived from my mnemonic. Is Infura not doing that for some reason?

1 Answer 1

9

If you're using truffle-hdwallet-provider, the documentation says this:

By default, the HDWalletProvider will use the address of the first address that's generated from the mnemonic. If you pass in a specific index, it'll use that address instead. Currently, the HDWalletProvider manages only one address at a time, but it can be easily upgraded to manage (i.e., "unlock") multiple addresses.

EDIT

Actually, it looks like this has already been done. See https://github.com/trufflesuite/truffle-hdwallet-provider/blob/master/index.js#L10:

function HDWalletProvider(mnemonic, provider_url, address_index=0, num_addresses=1) {

It looks like you can just pass a fourth parameter. E.g.

new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/ll2k3jdlKDl", 0, 10)
6
  • Do you know how to "unlock" multiple addresses? The documentation is not clear to me. Or an alternative to HDWalletProvider if its impossible?
    – ted oland
    Feb 28, 2018 at 22:43
  • See my edit. It looks like someone already did that.
    – user19510
    Feb 28, 2018 at 22:46
  • This looks like the commit that added support for multiple accounts, but the README was not updated: github.com/trufflesuite/truffle-hdwallet-provider/commit/….
    – user19510
    Feb 28, 2018 at 22:48
  • Thanks, if anyone is wondering i copied and pasted that into my node_modules/truffle-hdwallet-provider/index.js and it worked!
    – ted oland
    Feb 28, 2018 at 22:52
  • The issue is that the GitHub code is updated to support multiple accounts, but npm has not been updated. @tedoland instead of changing the code, try this: npm install --save-dev git+github.com/trufflesuite/truffle-hdwallet-provider.git#71520a2 Mar 8, 2018 at 17:52

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.