shmoula
shmoula

Reputation: 1083

Watch address with bitcoinj

I'm trying to use bitcoinj as a simple address watcher. I'm using WalletAppKit, into which I add address:

Address address = new Address(params, "mu69XXXYYYZZZggrHgaH");
kit.wallet().addWatchedAddress(address);

I used ForwardingService as an example - I have working watcher for incoming transactions (I run application and send amount to watching address, so onCoinsReceived() event is fired and I can see pending transaction).

After some time, when transaction is confirmed, I run the same code and I see that wallet balance is 0 and I'm unable to get any info about that address. Is there way how to do that (sure it is, but can someone show me - how)? I just'd like to watch some address and see balance at it.

Upvotes: 2

Views: 1383

Answers (1)

Dirk Jäckel
Dirk Jäckel

Reputation: 3025

To get the current balance for an address you need to redownload the SPVBlockchain after adding that address to the wallet.

If you want to see future spendigs to that adress you need to add this adress via addWatchedAddress() and continue to download the SPVBlockchain. You need to install a WalletEventListener to be notified about changes as they happen. Override onCoinsReceived() in your WalletEventListener().

Upvotes: 3

Related Questions