I have the following test Mnemonic:

stable primary already collect buffalo bike into robust fury cement proof agree neither blouse course

From this I can generate a BIP39 Wallet: https://iancoleman.io/bip39/

From this I can get all the private keys of the derived addresses (if you scroll down to the bottom).

But I'm not sure what format they're in.

The library, bitconjs-lib does the following:

const ONE = Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex')
keyPair = ECPair.fromPrivateKey(ONE)


But the private keys generated by https://iancoleman.io/bip39/ do not match the length required by bitcoinjs-lib


The mnemonic represents a BIP32 extended private key: xprv9s21ZrQH143K4BbpSvRBDykoXLhwtznbp7qAfKVLw1QdJtJsmgS5rZJfSgZNtgk7e39uRNiYHbcRQnYvruqfftfG6WFmuiCspehEz1VS3YM

The function you are calling accepts a regular private key.

You can derive child private keys from the extended private key and use these to generate addresses.

It it be possible to derive the corresponding private key of either the children of this extended private key or the corresponding private key itself using the toWIF method in the bip32 JS library. See https://github.com/bitcoinjs/bip32/blob/master/index.js

You can see some examples of the use of BIP32 here: https://github.com/bitcoinjs/bitcoinjs-lib/blob/a6f2cc2924df170537f0b588254178f5445d7dc8/test/integration/bip32.js

  • Thanks so much @Thorkil, just one last question: which line in the file you added shows a derivation to a regular private key? – timothyylim Jan 8 at 12:01
  • Can you call this? const seed = bip39.mnemonicToSeed(mnemonic); const node = bip32.fromSeed(seed); const privateKey = node.toWIF(); – Thorkil Værge Jan 8 at 13:43
  • that worked! Just for future reference, I used the wif node module to decode it to hex. – timothyylim Jan 9 at 16:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.