<p>You can refer to this source code.
<a href="https://github.com/tatumio/tatum-java/blob/master/src/main/java/io/tatum/wallet/Address.java#L24" rel="nofollow noreferrer">https://github.com/tatumio/tatum-java/blob/master/src/main/java/io/tatum/wallet/Address.java#L24</a></p>

CC BY-SA 4.0
2020-12-25T09:23:39.530Z
2020-12-25T09:23:39.530Z
tiennv
<p>As Watching wallet is a wallet which does not have private key. It is created with the help of public key. So, for generating addresses from extended public key for watch-only wallet, First of all you need to first create the watch-only wallet by that extended public key. and then you can simply derive the addresses from that one by one. </p>

<p>Sample code is shown below:</p>

<pre>
// Specify the Network Parameters for mainnet or testnet
NetworkParameters params = NetworkParameters.prodNet();

// Provide the public key from which you want to derive addresses
String xPub = "xpub6Cw8YA6Mko3xfkYpMQDZjGjgDTWUrJr87NBSiDPXqcmcSJTgxLXm3VCw3iQs4iC5ZrwpY3M21a43DZmiMzDXWzzhF1n7yxSXDnEHjJN6jwK";

// Create watching wallet, with the help of Wallet class
Wallet wallet = Wallet.fromWatchingKeyB58(params, xPub, DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS);

// Print the very first derived address from provided public key
System.out.println("Receiving Address : " + wallet.currentReceiveAddress());
</pre>

<p>The Output will be : </p>

<p><code>1L23PHmL38qjqbs75doB1VTSL3CKPwkPbC</code></p>

<p>You can get the public key from <a href="https://iancoleman.io/bip39/" rel="nofollow noreferrer">https://iancoleman.io/bip39/</a> and its all particular derived addresses. You can compare your first generated address from there, to make sure that you are getting correct addresses.</p>

<p>If you want to fetch first 20 or 30 Addresses then you can use given line in a loop. Provide loop limit upto 20 or 30 (which you want).</p>

<pre>    // Run this statement in a loop, where i is the loop variable.
    System.out.println(i + " : " + wallet.freshReceiveAddress());</pre>

<p>You can again compare these addresses from <a href="https://iancoleman.io/bip39/" rel="nofollow noreferrer">https://iancoleman.io/bip39/</a></p>

<p>NOTE: This wallet will be watching wallet, you can receive coins at these addresses but you can't spend those. Until and Unless you are not Signing the transaction to the particular private key, or you are not providing private key to this wallet.</p>

CC BY-SA 4.0
2018-05-25T12:59:24.940Z
2018-05-25T12:59:24.940Z
FairyRosie
<p>i am trying to generate addresses from Extended Public Key using bitcoinj but can't figure out, how can i possibly do this.</p>

<blockquote>
  <p>i need those addresses for watch-only wallet, those addresses were
  unsigned, right?</p>
</blockquote>

<p>further i can sign those addresses for sending transaction.</p>

<bitcoinj><java><xpub>
generate wallet addresses from extended public key
Zombie
# generate wallet addresses from extended public key

(Asked by: username_0 on 2018-03-26)

i am trying to generate addresses from Extended Public Key using bitcoinj but can't figure out, how can i possibly do this.

> i need those addresses for watch-only wallet, those addresses were
> unsigned, right?

further i can sign those addresses for sending transaction.

**Tags:** bitcoinj, java, xpub


---

## 2 answers

### Answer by username_1 on 2020-12-25. Score: 1 | Accepted answer

You can refer to this source code.
<https://github.com/tatumio/tatum-java/blob/master/src/main/java/io/tatum/wallet/Address.java#L24>


---

### Answer by username_2 on 2018-05-25. Score: 1

As Watching wallet is a wallet which does not have private key. It is created with the help of public key. So, for generating addresses from extended public key for watch-only wallet, First of all you need to first create the watch-only wallet by that extended public key. and then you can simply derive the addresses from that one by one.

Sample code is shown below:

```

// Specify the Network Parameters for mainnet or testnet
NetworkParameters params = NetworkParameters.prodNet();

// Provide the public key from which you want to derive addresses
String xPub = "xpub6Cw8YA6Mko3xfkYpMQDZjGjgDTWUrJr87NBSiDPXqcmcSJTgxLXm3VCw3iQs4iC5ZrwpY3M21a43DZmiMzDXWzzhF1n7yxSXDnEHjJN6jwK";

// Create watching wallet, with the help of Wallet class
Wallet wallet = Wallet.fromWatchingKeyB58(params, xPub, DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS);

// Print the very first derived address from provided public key
System.out.println("Receiving Address : " + wallet.currentReceiveAddress());

```

The Output will be :

`1L23PHmL38qjqbs75doB1VTSL3CKPwkPbC`

You can get the public key from <https://iancoleman.io/bip39/> and its all particular derived addresses. You can compare your first generated address from there, to make sure that you are getting correct addresses.

If you want to fetch first 20 or 30 Addresses then you can use given line in a loop. Provide loop limit upto 20 or 30 (which you want).

```
    // Run this statement in a loop, where i is the loop variable.
    System.out.println(i + " : " + wallet.freshReceiveAddress());
```

You can again compare these addresses from <https://iancoleman.io/bip39/>

NOTE: This wallet will be watching wallet, you can receive coins at these addresses but you can't spend those. Until and Unless you are not Signing the transaction to the particular private key, or you are not providing private key to this wallet.


---

