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:!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.

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')
Mike D
Mike D
June 12, 2018 11:59 AM

Related Questions

Time stamping of Transactions

Updated July 26, 2017 02:27 AM