1

Various block explorers exist, which offer REST APIs. So far been using blockchain.info and btc.com

Here is what we have:
- List of bitcoin addresses

Here is what can easily be got with that info:
- Historic list of transactions (hashes, or IDs) for the given addresses
- I can also discover which input or output was OUR address, and therefore:
- value, and whether the transaction was being sent or received

Now, here's what we need to obtain:
- the OTHER (to/from) address!

So:
How can you use a transaction ID to obtain BOTH the sender's and receiver's wallet address - with some kind of REST API preferably?

(...knowing that sometimes transaction IDs are associated with multiple inputs and multiple outputs)

Endpoint references:
https://blockchain.info/q
https://btc.com/api-doc

3 Answers 3

1

The Bitcoin system doesn't have a "sender's address". You can walk the transaction history to find out what destination the coins you were paid was last sent to but that is not a "sender's address".

Imagine if you had a magic wand you could wave over any package you received in the mail that would tell you where it was last mailed before you. You wave the wand over a package and find it was last mailed to a large distribution warehouse in china. Is this the sender's address? No. You bought the package from a shop in New York that purchased it for drop shipment from a distributor in Texas that fulfilled it out of a third party operated warehouse in Seattle, who recently pulled it out of a container from transoceanic shipment from the warehouse in china that your wand returned.

The previous to address might be useful information, just like the wand example-- but it is not the sender-- or at least not necessarily so--, it is not a return or refund address. And this failure to map to the sender is not a fringe situation, just like the wand returning someone other than the party who sold you something would not be fringe: people frequently pay bitcoin's out of third parties wallets.

-1

There is a field named "signature script" in the inputs.Signature script includes the sender's full (unhashed) public key,see:Bitcoin Developer Guide.You can get the sender's wallet address from the public key. In the outputs there is a field named "pubkey script" which contains the receiver's wallet address.

6
  • On BTC: signature script field --- "script_hex" , pubkey script field --- addresses:
    – Bill
    May 18, 2018 at 18:57
  • 2
    THIS IS NOT THE SENDER'S ADDRESS! Suppose Alice deposits bitcoins into an exchange and then Bill asks the exchange to pay Charley, if the exchange uses the coins Alice deposited, the "sender's address" will be Alice's deposit address even though Bill is the sender. Sending to that address will credit Alice, not Bill. May 18, 2018 at 21:20
  • What do you mean "THIS"?
    – Bill
    May 18, 2018 at 21:33
  • The address you get if you follow the procedure above. It is actually the receiving address of the transaction that funded the wallet that made the payment, which is not always the sender's address. See my example above. May 18, 2018 at 22:27
  • 1
    @Maz Bitcoin does not have a concept of a "sender address". If you want to know who paid you, give a different address for each invoice/expected payment. If you want to be able to refund people, ask them for a refund address before they pay you. Do not guess the sender's address based on the transaction; the information is not there. Sep 4, 2018 at 22:11
-2

You have to crawl the transactions,which will give you Vout addresses i.e receiver address

and to know the sender address you have to Crawl Vin txid and match the Vout address with "vout"and "n" parameter of raw transaction which will be you sender address. You can check the link which will show you how this is done in python 2.7

Your Answer

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

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