<p>Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:</p>

<blockquote>
  <p>If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.</p>
</blockquote>

<p>(<a href="https://bitcoinj.github.io/javadoc/0.12/org/bitcoinj/core/AbstractWalletEventListener.html#onCoinsReceived-org.bitcoinj.core.Wallet-org.bitcoinj.core.Transaction-org.bitcoinj.core.Coin-org.bitcoinj.core.Coin-" rel="nofollow">Source.</a>)</p>

<p>Use something like this:</p>

<pre><code>public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
            DefaultCoinSelector.isSelectable(transaction) {
                // do something here
            }
        }
    });
}
</code></pre>

CC BY-SA 3.0
2015-10-03T00:27:54.387Z
2015-10-03T17:54:39.400Z
2015-10-03T17:54:39.400Z
Nick ODell
<p>I need to know when my local wallet receives coins... but <code>onCoinsReceived</code> is invoked as soon as a transaction on my wallet is visible. How do I get notified when coins have been received and are spendable?</p>

<wallet><bitcoinj><receiving>
Bitcoinj: How to get notified when coins are received
j3d
# Bitcoinj: How to get notified when coins are received

(Asked by: username_0 on 2015-10-02)

I need to know when my local wallet receives coins... but `onCoinsReceived` is invoked as soon as a transaction on my wallet is visible. How do I get notified when coins have been received and are spendable?

**Tags:** wallet, bitcoinj, receiving


---

## 1 answers

### Answer by username_1 on 2015-10-03. Score: 1 | Accepted answer

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

> If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

([Source.](https://bitcoinj.github.io/javadoc/0.12/org/bitcoinj/core/AbstractWalletEventListener.html#onCoinsReceived-org.bitcoinj.core.Wallet-org.bitcoinj.core.Transaction-org.bitcoinj.core.Coin-org.bitcoinj.core.Coin-))

Use something like this:

```
public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
            DefaultCoinSelector.isSelectable(transaction) {
                // do something here
            }
        }
    });
}

```


---

