2

Watch-only wallet can only receive payments but not spend the available coins. I am using bitcoinj (in Java).

Can anyone please tell me that How to create watching addresses from available xPub key? where wallet can receive payments? and how to check the list of watching addresses which are related to that particular xPub key. Thanks in Advance

2

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/

Good Luck!

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.