<p>For future reference:
In bitcoinJ (java version) the input/output addresses of transactions are located in TransactionInput and TransactionOutput objects.</p>

<p>For example: for Transaction tx:</p>

<pre><code>List&lt;TransactionInput&gt; inputs = tx.getInputs();
List&lt;TransactionOutput&gt; outputs = tx.getOutputs();

for(TransactionOutput out : outputs){
    System.out.println(out.getAddressFromP2PKHScript(params));
    System.out.println(out.getAddressFromP2SH(params));
}

for(TransactionInput in : inputs){
    System.out.println(in.getFromAddress());
}
</code></pre>

<p>Keep in mind that some transactions might not have an input address.
Here is the github description of getFromAddress() method:</p>

<blockquote>
  <p>Convenience method that returns the from address of this input by parsing the scriptSig. The concept of a "from address" is not well defined in Bitcoin and you should not assume that senders of a transaction can actually receive coins on the same address they used to sign (e.g. this is not true for shared wallets).</p>
</blockquote>

CC BY-SA 3.0
2016-01-21T10:09:42.357Z
2016-01-21T10:19:50.310Z
2016-01-21T10:19:50.310Z
kpurens
<p>You can see the addresses that sent and received money when looking at a transaction on most services. For example:</p>

<p><a href="https://blockchain.info/tx/c6cb02e70442275ffb7b35cc8a9416323ff7e01b5378abc20ae7f5b6e7617884" rel="nofollow">https://blockchain.info/tx/c6cb02e70442275ffb7b35cc8a9416323ff7e01b5378abc20ae7f5b6e7617884</a></p>

<p>The big green arrow shows the transfer from one address (1B898F2tcWHX1LZWWfD21FRzqWrtXLocXN) to the 2 others. Programmatically you could use an API that returns JSON with equivalent information:</p>

<p><a href="https://api.blockcypher.com/v1/btc/main/txs/c6cb02e70442275ffb7b35cc8a9416323ff7e01b5378abc20ae7f5b6e7617884" rel="nofollow">https://api.blockcypher.com/v1/btc/main/txs/c6cb02e70442275ffb7b35cc8a9416323ff7e01b5378abc20ae7f5b6e7617884</a></p>

<p>However it isn't straightforward to extract this information when looking at a raw transaction as the addresses are embedded in the script.</p>

CC BY-SA 3.0
2014-05-25T19:12:12.497Z
2014-05-25T19:12:12.497Z
Matthieu
<p>I am using bitcoinj (java implementation). I have read many answers here but none of them answers my question. 
How to get senders address using bitcoinj?</p>

<p>I have transaction variable tx. I can get it's hash, I have used this as well: <a href="https://blockchain.info/tx/myTXhash" rel="nofollow">https://blockchain.info/tx/myTXhash</a> and it showed me the transactions. The problem is not even that web is showing me the sender. </p>

<p><strong>BUT:</strong> if I use that generated .wallet file and open it with multibit (bitcoin wallet) I can see there, under transactions, from who were the money sent. That means there is a way how to get senders address, but HOW? </p>

<p><strong>EDIT:</strong> I was mistaken, multibit does not know from who the money came from, I was just confused because it showed me it was sent to the right address (but that was set up by me in args).</p>

<p><strong>But is there any possibility to get the message somehow from client to know if it is him who sent the money?</strong></p>

CC BY-SA 3.0
2014-05-23T18:36:43.130Z
Do you mean getting the Bitcoin address that sent the money or somehow getting a name?
Matthieu
CC BY-SA 3.0
2014-05-25T15:28:55.947Z
Yes I mean Bitcoin address that sent the money. Or some other way how to check if the money came from that person. Consider it as a wallet which is receiving money constantly, but I need to check if it is coming from the ones who wants to access on a web.
Ondrej 'zatokar' Tokár
<transactions><bitcoinj>
How to get senders address with bitcoinj (no duplicate)?
Ondrej 'zatokar' Tokár
# How to get senders address with bitcoinj (no duplicate)?

(Asked by: username_0 on 2014-05-23)

I am using bitcoinj (java implementation). I have read many answers here but none of them answers my question.
How to get senders address using bitcoinj?

I have transaction variable tx. I can get it's hash, I have used this as well: <https://blockchain.info/tx/myTXhash> and it showed me the transactions. The problem is not even that web is showing me the sender.

**BUT:** if I use that generated .wallet file and open it with multibit (bitcoin wallet) I can see there, under transactions, from who were the money sent. That means there is a way how to get senders address, but HOW?

**EDIT:** I was mistaken, multibit does not know from who the money came from, I was just confused because it showed me it was sent to the right address (but that was set up by me in args).

**But is there any possibility to get the message somehow from client to know if it is him who sent the money?**

**Tags:** transactions, bitcoinj

> **Comments:**
> **username_1**: Do you mean getting the Bitcoin address that sent the money or somehow getting a name?  
> **username_0**: Yes I mean Bitcoin address that sent the money. Or some other way how to check if the money came from that person. Consider it as a wallet which is receiving money constantly, but I need to check if it is coming from the ones who wants to access on a web.  

---

## 2 answers

### Answer by username_2 on 2016-01-21. Score: 4

For future reference:
In bitcoinJ (java version) the input/output addresses of transactions are located in TransactionInput and TransactionOutput objects.

For example: for Transaction tx:

```
List<TransactionInput> inputs = tx.getInputs();
List<TransactionOutput> outputs = tx.getOutputs();

for(TransactionOutput out : outputs){
    System.out.println(out.getAddressFromP2PKHScript(params));
    System.out.println(out.getAddressFromP2SH(params));
}

for(TransactionInput in : inputs){
    System.out.println(in.getFromAddress());
}

```

Keep in mind that some transactions might not have an input address.
Here is the github description of getFromAddress() method:

> Convenience method that returns the from address of this input by parsing the scriptSig. The concept of a "from address" is not well defined in Bitcoin and you should not assume that senders of a transaction can actually receive coins on the same address they used to sign (e.g. this is not true for shared wallets).


---

### Answer by username_1 on 2014-05-25. Score: 1

You can see the addresses that sent and received money when looking at a transaction on most services. For example:

<https://blockchain.info/tx/c6cb02e70442275ffb7b35cc8a9416323ff7e01b5378abc20ae7f5b6e7617884>

The big green arrow shows the transfer from one address (1B898F2tcWHX1LZWWfD21FRzqWrtXLocXN) to the 2 others. Programmatically you could use an API that returns JSON with equivalent information:

<https://api.blockcypher.com/v1/btc/main/txs/c6cb02e70442275ffb7b35cc8a9416323ff7e01b5378abc20ae7f5b6e7617884>

However it isn't straightforward to extract this information when looking at a raw transaction as the addresses are embedded in the script.


---

