<p>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 <a href="https://github.com/bitcoinj/bitcoinj/pull/1563" rel="nofollow noreferrer">this</a></p>

CC BY-SA 4.0
2018-07-17T13:19:29.847Z
2018-07-17T13:19:29.847Z
Zombie
<p>Your problem seems similar to the given link:</p>

<p><a href="https://groups.google.com/forum/#!topic/bitcoinj/F7smdvlCbnE" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/bitcoinj/F7smdvlCbnE</a></p>

<p>Try to use bitcoinjs for the same extended public key. or try the provided solutions. </p>

<p>Hope this will work in your case.</p>

CC BY-SA 4.0
2018-06-12T11:42:17.147Z
how to use bitcoinjs for extended public key in java?
Black Panther
CC BY-SA 4.0
2018-06-12T11:24:41.613Z
2018-06-12T11:24:41.613Z
FairyRosie
<p>You can use <a href="https://github.com/mcdallas/cryptotools" rel="nofollow noreferrer">this</a> Python library.</p>

<pre><code>from btctools import Xpub

&gt;&gt;&gt; extended = Xpub.decode('xpub123...')
&gt;&gt;&gt; child = extended/0/0
&gt;&gt;&gt; child.key.to_address('P2WPKH')
'bc1q0xedk29m3z0ja0l5xl2avclrhkd8y9z5au5wyt'
</code></pre>

CC BY-SA 4.0
2018-06-12T20:25:38.557Z
how can use this python lib in java ?
Black Panther
CC BY-SA 4.0
2018-06-12T11:59:30.960Z
2018-06-12T11:59:30.960Z
Mike D
<p>I tried to use the following code:</p>

<pre><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());
</code></pre>

<p>But it doesn't return correct address. 
Any help here</p>

<bitcoin-core><bitcoin-core-development><bitcoinj><bitcoin-wallet-app>
How to derive segwit addresses from an extended public key?
Black Panther
# How to derive segwit addresses from an extended public key?

(Asked by: username_0 on 2018-06-11)

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

**Tags:** bitcoin-core, bitcoin-core-development, bitcoinj, bitcoin-wallet-app


---

## 3 answers

### Answer by username_1 on 2018-07-17. Score: 1 | Accepted answer

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](https://github.com/bitcoinj/bitcoinj/pull/1563)


---

### Answer by username_2 on 2018-06-12. Score: 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.

> **Comments:**
> **username_0**: how to use bitcoinjs for extended public key in java?  

---

### Answer by username_3 on 2018-06-12. Score: 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'

> **Comments:**
> **username_0**: how can use this python lib in java ?  

---

