Reading this thread about determining the sending address of a bitcoin transaction. I'm a bit confused, how do you differentiate between the change address and the "receiving" address of the last transaction?

txid = <relevant transaction id>
addresses = []
raw_tx = decoderawtransaction(getrawtransaction(txid))
for(input in raw_tx['vin']) {
  input_raw_tx = decoderawtransaction(getrawtransaction(input['txid']))
  addresses.push(input_raw_tx['vout'][input['vout']]['scriptPubKey']['addresses'] [0])

Would addresses not include other outputs that are unrelated to the sending address? I'm trying to build a block explorer and I'm uncertain how to determine which address sent coins in each transaction. Is it possible to tell?

  • Payments are not sent from addresses, they're only sent to addresses. Commented Aug 4, 2013 at 18:22
  • Is that to say there is no way to tell with 100% certainty which address signed a transaction into the network?
    – bvpx
    Commented Aug 4, 2013 at 21:30
  • 1
    You can tell which address(es) keys were used to sign the transaction, but that doesn't tell you who sent the transaction, only what keys were needed to sign it. Commented Aug 5, 2013 at 3:07
  • Let's say a website has online wallets, and each account is given an address which they can send coins to other addresses on the site from. Considering the site controls every RPC call of all of these addresses, and you always use the sendfrom command, is it true that you'd be able to tell which address signed each transaction? Is there any possibility for abuse if the users of the site don't have access to the private keys? (I'm thinking of making a color coin type app, with small transaction amounts, but very long delays between transactions to avoid spam of the network).
    – bvpx
    Commented Aug 5, 2013 at 5:14
  • I can't see how that would work, unless the site sends each transaction twice, first to the source it needs to send them from for the real send. To the extent you can send funds "from" an address, it must be the address those funds were last sent to. Also, I'm not sure this would help -- people wouldn't, in general, know transactions came from this site so even if this site could make the information reliable, people wouldn't know it was reliable and so couldn't rely on it. Commented Aug 5, 2013 at 6:43

2 Answers 2


Every output is identified by the hash of the transaction it is in, and the serial number of this output in the list of transaction outputs.

If an output is spent as the input of another transaction, the input of that transaction contains two fields, txid and vout, to specify the tx id and the serial number of that output.

In the code snippet you give, first input['txid'] is used to pinpoint the transaction, and then input['vout'] is used to find the specific output.

  • Okay, so when you're looking at a transaction, the vin array contains txid and vout metadata, so if you then look at that txid and find the vout with the same n value as vout you've found the output that refers to that exact transaction? Meaning you can be sure that if you're looking at the vout field of the transaction with the txid hash and n = vout then you've found the exact output that refers to that input? But can't addresses in the scriptPubKey array have more than one address?
    – bvpx
    Commented Aug 3, 2013 at 21:54
  • @bvpx: I'm not sure but I believe multisig outputs will have multiple addresses listed. Commented Aug 4, 2013 at 7:54

From the Bitcoin Wiki:

An input is a reference to an output in a different transaction.

A transaction can have multiple outputs, e.g., a normal one and the change, which specify the recipient address in their scriptPubKey. So usually to each output belongs one address, and the input specifies which output it redeems.

If an output specifies multiple destination addresses (which is rarely the case), only one of those can redeem the transaction. You can find out which one by looking at the scriptSig of the input.

  • Okay, so the addresses field in the scriptPubKey can potentially contain multiple addresses? What scriptSig specifically can allow this?
    – bvpx
    Commented Aug 3, 2013 at 21:57

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.