<p>I wrote this function using bitcoinJ</p>

<pre><code>public Wallet getWallet(ECKey ecKey) {
        Wallet wallet = walletAppKit.wallet();
        wallet.importKey(ecKey);
        wallet.addEventListener(new AbstractWalletEventListener() {
            @Override
            public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
                System.out.println("\nReceived tx " + tx.getHashAsString());
                System.out.println(tx.toString());
                System.out.println(wallet.getBalance());
            }
        });
        System.out.println("Address created:" + ecKey.toAddress(wallet.getNetworkParameters()));
        return wallet;
    }
</code></pre>

<p>Basically I am preparing the wallet to be used. I go to one of those testnet faucets to send some coinst to that wallet, and the event reaches the listener but prints that the balance in the wallet is 0.
This is what I see in the terminal:</p>

<blockquote>
  <p>3376017266d6e2924ae578c8af752edd5ccc9371c38a3b9304f149dfaba36f99: Seen
  by 2 peers. Pending/unconfirmed.
       in   PUSHDATA(72)[3045022100cd0f19af359abb49c429974122d2baa2d29d3975018b19d18a972d934d508e0e02207b42c2a07ddc540382266f03586299926fecf35c3f998609d1e229e7bf52df8801]
  PUSHDATA(33)[0363f08c5d814459ea2b8d0109b791cbd762ce266b9b6f2e02802d4934bf09d2a6]
            outpoint:e636ba115d9f0222e04a78cd856ebf0b184ba1a5279ecc1331241e30d44b28a3:0
       out  DUP HASH160 PUSHDATA(20)[5e9b9195b7aee85b53ade382f4f444a9d2522e26] EQUALVERIFY
  CHECKSIG 0.05922 BTC
       out  DUP HASH160 PUSHDATA(20)[4a88f0063671c6ddd1a3faa121d1b69f82f8dc82] EQUALVERIFY
  CHECKSIG 0.001 BTC</p>
  
  <p>Sep 17, 2015 11:29:17 PM org.bitcoinj.wallet.WalletFiles saveNow INFO:
  Saving wallet, last seen block is
  556391/00000000096e9b05c0986940553240db3d497900881bcc22df8bdad39144b053
  Sep 17, 2015 11:29:17 PM org.bitcoinj.wallet.WalletFiles
  saveNowInternal INFO: Save completed in 98msec 0</p>
</blockquote>

<p>So why getBalance() is returning me 0? Do I need to wait longer? How long?
Because I sued the debugger and i called wallet.getBalance() again and again but I don't see it changing, its always 0.</p>

CC BY-SA 3.0
2015-09-18T01:37:07.430Z
I'd wait until the transaction gets a few confirmations. You can check on a block explorer.
David Schwartz
CC BY-SA 3.0
2015-09-19T15:51:54.107Z
@David Schwartz You are right the transaction appeared and I can see my balance now thanks.
sfrj
<wallet><bitcoinj><java>
Why I can't see the balance increasing in my wallet?
sfrj
# Why I can't see the balance increasing in my wallet?

(Asked by: username_0 on 2015-09-17)

I wrote this function using bitcoinJ

```
public Wallet getWallet(ECKey ecKey) {
        Wallet wallet = walletAppKit.wallet();
        wallet.importKey(ecKey);
        wallet.addEventListener(new AbstractWalletEventListener() {
            @Override
            public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
                System.out.println("\nReceived tx " + tx.getHashAsString());
                System.out.println(tx.toString());
                System.out.println(wallet.getBalance());
            }
        });
        System.out.println("Address created:" + ecKey.toAddress(wallet.getNetworkParameters()));
        return wallet;
    }

```

Basically I am preparing the wallet to be used. I go to one of those testnet faucets to send some coinst to that wallet, and the event reaches the listener but prints that the balance in the wallet is 0.
This is what I see in the terminal:

> 3376017266d6e2924ae578c8af752edd5ccc9371c38a3b9304f149dfaba36f99: Seen
> by 2 peers. Pending/unconfirmed.
> in PUSHDATA(72)[3045022100cd0f19af359abb49c429974122d2baa2d29d3975018b19d18a972d934d508e0e02207b42c2a07ddc540382266f03586299926fecf35c3f998609d1e229e7bf52df8801]
> PUSHDATA(33)[0363f08c5d814459ea2b8d0109b791cbd762ce266b9b6f2e02802d4934bf09d2a6]
> outpoint:e636ba115d9f0222e04a78cd856ebf0b184ba1a5279ecc1331241e30d44b28a3:0
> out DUP HASH160 PUSHDATA(20)[5e9b9195b7aee85b53ade382f4f444a9d2522e26] EQUALVERIFY
> CHECKSIG 0.05922 BTC
> out DUP HASH160 PUSHDATA(20)[4a88f0063671c6ddd1a3faa121d1b69f82f8dc82] EQUALVERIFY
> CHECKSIG 0.001 BTC
>
> Sep 17, 2015 11:29:17 PM org.bitcoinj.wallet.WalletFiles saveNow INFO:
> Saving wallet, last seen block is
> 556391/00000000096e9b05c0986940553240db3d497900881bcc22df8bdad39144b053
> Sep 17, 2015 11:29:17 PM org.bitcoinj.wallet.WalletFiles
> saveNowInternal INFO: Save completed in 98msec 0

So why getBalance() is returning me 0? Do I need to wait longer? How long?
Because I sued the debugger and i called wallet.getBalance() again and again but I don't see it changing, its always 0.

**Tags:** wallet, bitcoinj, java

> **Comments:**
> **username_1**: I'd wait until the transaction gets a few confirmations. You can check on a block explorer.  
> **username_0**: @username_1 You are right the transaction appeared and I can see my balance now thanks.  

---

## 0 answers

