title: How to watch for transactions for an address in Bitcoinj (java)?
body: <p>My goal is to <strong>watch</strong> a public bitcoin address and print to the console whenever money is sent to that address. That's all. I'm taking an address previously generated in Bitcoin Core, for now. </p>
  
  <p>I'm doing the following:</p>
  
  <pre><code> NetworkParameters params = MainNetParams.get();
   Wallet wallet = Wallet.loadFromFile(file);
   BlockStore blockStore = new MemoryBlockStore(params);
   BlockChain chain = new BlockChain(params, wallet, blockStore);
  
   PeerGroup peerGroup = new PeerGroup(params, chain);
   peerGroup.addPeerDiscovery(new DnsDiscovery(params));
   peerGroup.setUseLocalhostPeerWhenPossible(true);
   peerGroup.startAsync();
  
   Address add = new Address(params, "1NpxxxxxxxxxxxxxxxaSC4");
   wallet.addWatchedAddress(add);
  
   wallet.addEventListener(new AbstractWalletEventListener() {
          @Override
          public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
              System.out.println("[main]: COINS RECIEVED!"); 
              System.out.println("\nReceived tx " + tx.getHashAsString());
              System.out.println(tx.toString());
          }
      });
  
   System.out.println("\nDone!\n");
   System.out.println(wallet.toString());
  </code></pre>
  
  <p>I have a feeling that I'm not handling the AbstractWalletEventListener correctly. When I send money to the address, I don't get the text I expect to see in the console. Instead, I just see the continuous stream of "peer announced new transaction" from the [NioClientManager] from the peerGroup.startAsync() method. </p>
  
  <p>What am I doing wrong and how can I correct it? I've spent way more time than I should have on something that seems like it should be such a simple task. </p>
  
  <p>PS. The file I'm calling for "loadFromFile" is just a blank, default wallet file generated by bitcoinj. Nothing special about it. </p>
  
  <p>Edit: Also, I'm not looking to see the total balance of the wallet. I only want to know when -new- transactions come in. Old ones are irrelevant in my program. </p>