<p>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.</p>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2013-08-03T21:54:20.400Z
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
CC BY-SA 3.0
2013-08-04T07:54:41.803Z
@bvpx: I'm not sure but I believe multisig outputs will have multiple addresses listed.
Meni Rosenfeld
CC BY-SA 3.0
2013-08-03T21:36:17.363Z
2013-08-03T21:36:17.363Z
Meni Rosenfeld
<p>From <a href="https://en.bitcoin.it/wiki/Transactions" rel="nofollow">the Bitcoin Wiki</a>:</p>

<blockquote>
  <p>An input is a reference to an output in a different transaction. </p>
</blockquote>

<p>A transaction can have <em>multiple</em> 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.</p>

<p>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.</p>

CC BY-SA 3.0
2013-08-03T21:57:33.320Z
Okay, so the `addresses` field in the `scriptPubKey` can potentially contain multiple addresses? What `scriptSig` specifically can allow this?
bvpx
CC BY-SA 3.0
2013-08-03T21:28:52.977Z
2013-08-03T21:28:52.977Z
Malte
<p>Reading <a href="https://bitcoin.stackexchange.com/questions/2667/whats-the-best-way-for-a-website-to-detect-payments-from-green-addresses/5981#5981">this thread</a> 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?</p>

<pre><code>txid = &lt;relevant transaction id&gt;
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])
}
</code></pre>

<p>Would <code>addresses</code> 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?</p>

CC BY-SA 3.0
2013-08-04T18:22:33.537Z
Payments are not sent from addresses, they're only sent *to* addresses.
David Schwartz
CC BY-SA 3.0
2013-08-04T21:30:59.723Z
Is that to say there is no way to tell with 100% certainty which address signed a transaction into the network?
bvpx
CC BY-SA 3.0
2013-08-05T03:07:54.110Z
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.
David Schwartz
CC BY-SA 3.0
2013-08-05T05:14:03.647Z
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
CC BY-SA 3.0
2013-08-05T06:43:38.947Z
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.
David Schwartz
CC BY-SA 3.0
2013-08-05T18:20:16.367Z
Could the site not provide a signed message to prove it owns an address? The idea is that the "color coin" within this network of people should not be sent outside of the network and is tracked by the site itself, which validates sending and receiving bits of that color coin amongst users of the site. It's simply using the blockchain to recognize these transactions publicly.
bvpx
CC BY-SA 3.0
2013-08-05T19:26:58.033Z
Yeah, but I think that would be an example of an entire class of silly answers to the question you asked. You can be 100% certain that a payment was sent from a specified address if **you** sent it too. Yes, if some out of band mechanism you trust, assures you of something, then you can be certain of it.
David Schwartz
CC BY-SA 3.0
2013-08-06T03:57:10.000Z
possible duplicate of [When a transaction is split into two outputs, how does the network "know" you're the owner of the "change" address?](http://bitcoin.stackexchange.com/questions/12468/when-a-transaction-is-split-into-two-outputs-how-does-the-network-know-youre)
Stephen Gornick
CC BY-SA 3.0
2013-08-06T16:38:49.850Z
@Stephen Gornick the questions are entirely different, this is a blockchain data structure question whereas the last question was about the distinction between an address, an account, and the way the private key works in the wallet. They are sort of similar, though.
bvpx
<transactions><blockchain>
Can you be 100% certain that a payment was sent from a specific address?
bvpx
# Can you be 100% certain that a payment was sent from a specific address?

(Asked by: username_0 on 2013-08-03)

Reading [this thread](https://bitcoin.stackexchange.com/questions/2667/whats-the-best-way-for-a-website-to-detect-payments-from-green-addresses/5981#5981) 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?

**Tags:** transactions, blockchain

> **Comments:**
> **username_1**: Payments are not sent from addresses, they're only sent *to* addresses.  
> **username_0**: Is that to say there is no way to tell with 100% certainty which address signed a transaction into the network?  
> **username_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.  
> **username_0**: 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).  
> **username_1**: 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.  
> **username_0**: Could the site not provide a signed message to prove it owns an address? The idea is that the "color coin" within this network of people should not be sent outside of the network and is tracked by the site itself, which validates sending and receiving bits of that color coin amongst users of the site. It's simply using the blockchain to recognize these transactions publicly.  
> **username_1**: Yeah, but I think that would be an example of an entire class of silly answers to the question you asked. You can be 100% certain that a payment was sent from a specified address if **you** sent it too. Yes, if some out of band mechanism you trust, assures you of something, then you can be certain of it.  
> **username_2**: possible duplicate of [When a transaction is split into two outputs, how does the network "know" you're the owner of the "change" address?](http://bitcoin.stackexchange.com/questions/12468/when-a-transaction-is-split-into-two-outputs-how-does-the-network-know-youre)  
> **username_0**: @username_2 the questions are entirely different, this is a blockchain data structure question whereas the last question was about the distinction between an address, an account, and the way the private key works in the wallet. They are sort of similar, though.  

---

## 2 answers

### Answer by username_3 on 2013-08-03. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: 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?  
> **username_3**: @username_0: I'm not sure but I believe multisig outputs will have multiple addresses listed.  

---

### Answer by username_4 on 2013-08-03. Score: 2

From [the Bitcoin Wiki](https://en.bitcoin.it/wiki/Transactions):

> 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.

> **Comments:**
> **username_0**: Okay, so the `addresses` field in the `scriptPubKey` can potentially contain multiple addresses? What `scriptSig` specifically can allow this?  

---

