user6024: 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?

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

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

6024: <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>
 6177: <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>
 575: <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>
