<p>I found out in the end how to do it, here you can see:</p>

<pre><code>    wallet.addEventListener(new AbstractWalletEventListener(){
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            String hash = tx.getHashAsString();
            long received = newBalance.value-prevBalance.value;
            String address = null;
            for (TransactionOutput txop : tx.getOutputs()){
                if (txop.isMine(wallet)){
                    address = txop.getScriptPubKey().getToAddress(params).toString();
                }
            }
            int UserID = MySQL.getUserIDbyAddress(address);
            // Code...
        }
    });
</code></pre>

CC BY-SA 3.0
2015-05-08T21:57:51.663Z
2015-05-08T21:57:51.663Z
Anzure
<p>I am using BitcoinJ and wondering who user that I should credit, all users have their own receiving addresses. Please post an example also, if you have time. :)
Current code:</p>

<pre><code>    wallet.addEventListener(new AbstractWalletEventListener(){
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            String txid = tx.getHashAsString();
            long received = newBalance.value-prevBalance.value;
            String address; // The receive address that the payment was sent to.
            int UserID = MySQL.getUserIDbyAddress(address);
            // Here will I credit the user.
        }
    });
</code></pre>

CC BY-SA 3.0
2015-05-07T06:27:14.983Z
I'm afraid I don't understand the question. It sounds like you have some piece of information and you want to get some other piece, but it's not clear to me exactly what those pieces are.
Nate Eldredge
CC BY-SA 3.0
2015-05-07T14:43:52.373Z
@NateEldredge I think he wants the address that recieved the payment, given the arguments to onCoinsReceived. Is that correct, HydroTekZ?
Nick ODell
CC BY-SA 3.0
2015-05-08T11:00:15.640Z
It is very correct, @NickOdell. NateEldredge, I want to get the address that recived the payment.
Anzure
CC BY-SA 3.0
2015-05-08T14:52:56.270Z
Please don't offer people money. It's against SE's policies.
Nick ODell
CC BY-SA 3.0
2015-05-08T19:22:55.557Z
Sorry, never mind about the money then... Anyways, do somebody know how I can get the address that recive a payment?
Anzure
<bitcoinj>
How do I get the address that received a payment?
Anzure
# How do I get the address that received a payment?

(Asked by: username_0 on 2015-05-06)

I am using BitcoinJ and wondering who user that I should credit, all users have their own receiving addresses. Please post an example also, if you have time. :)
Current code:

```
    wallet.addEventListener(new AbstractWalletEventListener(){
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            String txid = tx.getHashAsString();
            long received = newBalance.value-prevBalance.value;
            String address; // The receive address that the payment was sent to.
            int UserID = MySQL.getUserIDbyAddress(address);
            // Here will I credit the user.
        }
    });

```

**Tags:** bitcoinj

> **Comments:**
> **username_1**: I'm afraid I don't understand the question. It sounds like you have some piece of information and you want to get some other piece, but it's not clear to me exactly what those pieces are.  
> **username_2**: @username_1 I think he wants the address that recieved the payment, given the arguments to onCoinsReceived. Is that correct, HydroTekZ?  
> **username_0**: It is very correct, @username_2. username_1, I want to get the address that recived the payment.  
> **username_2**: Please don't offer people money. It's against SE's policies.  
> **username_0**: Sorry, never mind about the money then... Anyways, do somebody know how I can get the address that recive a payment?  

---

## 1 answers

### Answer by username_0 on 2015-05-08. Score: 1 | Accepted answer

I found out in the end how to do it, here you can see:

```
    wallet.addEventListener(new AbstractWalletEventListener(){
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            String hash = tx.getHashAsString();
            long received = newBalance.value-prevBalance.value;
            String address = null;
            for (TransactionOutput txop : tx.getOutputs()){
                if (txop.isMine(wallet)){
                    address = txop.getScriptPubKey().getToAddress(params).toString();
                }
            }
            int UserID = MySQL.getUserIDbyAddress(address);
            // Code...
        }
    });

```


---

