How to derive segwit addresses from an extended public key?

by Black Panther   Last Updated July 17, 2018 09:27 AM

I tried to use the following code:

    DeterministicKey key = DeterministicKey.deserializeB58(null , "xpub...", MAINNET);



    DeterministicHierarchy hierarchy = new DeterministicHierarchy(key)
;
    DeterministicKey chain = hierarchy.deriveChild(key.getPath(), false, false, new ChildNumber(0, false));
    DeterministicKey index = hierarchy.deriveChild(chain.getPath(), false, false, new ChildNumber(0, false));
    SegwitAddress segwitAddress = SegwitAddress.fromHash(MAINNET, index.getPubKeyHash());

But it doesn't return correct address. Any help here



Answers 2


Your problem seems similar to the given link:

https://groups.google.com/forum/#!topic/bitcoinj/F7smdvlCbnE

Try to use bitcoinjs for the same extended public key. or try the provided solutions.

Hope this will work in your case.

FairyRosie
FairyRosie
June 12, 2018 11:24 AM

You can use this Python library.

from btctools import Xpub

>>> extended = Xpub.decode('xpub123...')
>>> child = extended/0/0
>>> child.key.to_address('P2WPKH')
'bc1q0xedk29m3z0ja0l5xl2avclrhkd8y9z5au5wyt'
Mike D
Mike D
June 12, 2018 11:59 AM

Related Questions




Time stamping of Transactions

Updated July 26, 2017 02:27 AM