1

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

1

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

0

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.

  • how to use bitcoinjs for extended public key in java? – Black Panther Jun 12 '18 at 11:42
0

You can use this Python library.

from btctools import Xpub

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

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.