2

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 to get that kind of information?

1 Answer 1

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());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.