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

3 Answers 3


Zpub's would be needed for native segwit addresses. And current bitcoinj master branch does not support Zpub, it support xpub and xpub's would always derive to legacy addresses. Give a try to Segwit branch that may helps. Also take a look at this


Your problem seems similar to the given link:


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

Hope this will work in your case.

  • how to use bitcoinjs for extended public key in java? Jun 12, 2018 at 11:42

You can use this Python library.

from btctools import Xpub

>>> extended = Xpub.decode('xpub123...')
>>> child = extended/0/0
>>> child.key.to_address('P2WPKH')
  • how can use this python lib in java ? Jun 12, 2018 at 20:25

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.