I want to create bitcoin address from extended public key, without exposing private key but did not get any success till now. Do someone know how to do it? I am using bitcore-lib package

  • can you provide any code and the problems you're having?
    – JBaczuk
    Jul 24 '18 at 13:36

According to BIP32 you're trying to generate a non-hardened child address, see BIP32 - Public parent key → public child key.

Using bitcore-lib, to derive a non-hardened child public key and a P2PKH address:

var bitcore = require('bitcore-lib');
var Address = bitcore.Address;
var PublicKey = bitcore.PublicKey;
var Networks = bitcore.Networks;

var hdPublickey = new bitcore.HDPublicKey('tpubD6NzVbkrYhZ4XLMmry7XriYJ6Xgx1vQqoUZHLUXQPDB32n7pQYaWSMpRttm2sHzYjsQqrsAZYyJCmoEJB51oSdqZxq7epGjP4vHriCYz7Tp');
var orderPublickey = hdPublickey.deriveChild("m/44/145/0/0");
var pubkey = new PublicKey(orderPublickey.publicKey);
var address = Address.fromPublicKey(pubkey, Networks.testnet);
console.log("address", address);

address <Address: mkVBk6gZ7rBLYXvpdcKwTEq6SjHvSeLwZ8, type: pubkeyhash, network: testnet>

  • could we convert this publicKey into bitcoin base58 address? Jul 24 '18 at 13:51
  • I got this method bitcore.Address.fromPublicKey() but it is not working Jul 24 '18 at 13:58
  • What is it doing? Also, try var address = Address(publicKey, 'mainnet').toString(); Also it depends on what type of address you want (p2sh or p2pkh)
    – JBaczuk
    Jul 24 '18 at 14:02
  • please define Address? do you have any working code that can generate bitcoin address from xpub? Jul 24 '18 at 14:05
  • 1
    ok thanks @JBaczuk Nov 18 '19 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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