I want to create public addresses in offline browser from master public key so that owner of master private can access the funds available in child address. but I am not able to understand how to use this bitcoinjs-lib. how to create master private key, master public key and every time i click on button it generate new child bitcoin address.

Help is appreciated

1 Answer 1


I'm doing something similar but using segwit addresses (BIP49). If you are using BIP32 with a standard derivation of m/0'/0/0 you could do something like this - See: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L35

//get a mnemonic, then seed, then root.
var mnemonic = bip39.generateMnemonic();
var seed = bip39.mnemonicToSeed(mnemonic);
var root = bitcoin.HDNode.fromSeedBuffer(seed);

//root can be transformed to your xpub and xprv
var xprv = root.toBase58();
var xpub = root.neutered().toBase58();

//You can then create the address with a derivation of m/0'/0/0
var change = 0; //0 for external (receive), 1 for internal (change)
var index = 0; //the index of the address you want to generate
var keypair = root.deriveHardened(0).derive(change).derive(index);
//or keypair = root.derivePath("m/0'/" + change + "/" + index);
var address = keypair.getAddress();

If your derivation for your addresses is m/0' (then external, then the index) Then you have the xpub for the parent m and can store xpub of m/0'/0 on the server. On the server when a user clicks the button it generates the address n/0, where n = your xpub of m/0'/0.

  • I have one question for you. Scenario : If bitcoin address on x level down offline on web browser using parent hdXpublickey which i donot know because of offline then i retrieve bitcoin from child address using extended private key without knowing path on server when sender sends its fund.
    – rahul
    Sep 6, 2017 at 16:44
  • If you're building an HD implementation you should have the parent xprv stored on your computer. Using that you can derive the private keys for all child accounts. You shouldn't be generating addresses from a random derivation on the user-side, it would take you forever to iterate over all the possible derviations.
    – wmpedersen
    Sep 7, 2017 at 15:09
  • See my edit of the main for a little more explanation
    – wmpedersen
    Sep 7, 2017 at 15:20
  • storing private key on server it question of security. One more thing how Tezos work. Its a big question in my mind.Do you have any idea?
    – rahul
    Sep 11, 2017 at 6:25
  • Is bitcoinjs lib can br used for bitcoin cash?
    – rahul
    Sep 11, 2017 at 6:40

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.