<p>You should get the list of inputs, this is a snippet code using BitcoinJ to get input and outputs addresses:                    </p>

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

for (TransactionOutput out : outputs) {
   System.out.println("addresses in output " + out.getAddressFromP2PKHScript(params));
}
for (TransactionInput in : inputs) {
    System.out.println("addresses in input " + in.getFromAddress());
}
</code></pre>

CC BY-SA 3.0
2016-02-04T13:30:59.067Z
2016-02-05T15:00:47.720Z
2016-02-05T15:00:47.720Z
Badr Bellaj
<p>I am trying to obtain the addresses of entry of a transaction when I receive money, but I have not found the way. I have tried to create an address with the bytes obtained by calling <code>TransactionInput.getScriptSig().getPubKey()</code>, but I've only obtained a ScriptException. If I call <code>TransactionInput.getFromAddress()</code> (deprecated) the code is frozen. I don't want to have to make a call to the API of block explorer, it is too cumbersome. Is there any way of doing this? As it parses the transaction <a href="https://www.blochain.info" rel="nofollow">blockhain.info</a> to get that kind of information?</p>

<transactions><address><bitcoinj><transaction-input>
How can I get the input addresses of a transaction in Java?
Ander Acosta
# How can I get the input addresses of a transaction in Java?

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

I am trying to obtain the addresses of entry of a transaction when I receive money, but I have not found the way. I have tried to create an address with the bytes obtained by calling `TransactionInput.getScriptSig().getPubKey()`, but I've only obtained a ScriptException. If I call `TransactionInput.getFromAddress()` (deprecated) the code is frozen. I don't want to have to make a call to the API of block explorer, it is too cumbersome. Is there any way of doing this? As it parses the transaction [blockhain.info](https://www.blochain.info) to get that kind of information?

**Tags:** transactions, address, bitcoinj, transaction-input


---

## 1 answers

### Answer by username_1 on 2016-02-04. Score: 1

You should get the list of inputs, this is a snippet code using BitcoinJ to get input and outputs addresses:

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

for (TransactionOutput out : outputs) {
   System.out.println("addresses in output " + out.getAddressFromP2PKHScript(params));
}
for (TransactionInput in : inputs) {
    System.out.println("addresses in input " + in.getFromAddress());
}

```


---

