3

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?

  • Do you mean getting the Bitcoin address that sent the money or somehow getting a name? – Matthieu May 23 '14 at 18:36
  • 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 May 25 '14 at 15:28
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).

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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