<p>So a transaction will have multiple vins, if it takes multiple UTXOs to send the value.</p>

<p>So let's say you in the past have received 10BTC from X, and 5BTC from Y.</p>

<p>You now need to send 11BTC to Kate.</p>

<p>What it will do is, </p>

<p>it will send out the 10BTC from X, as this is an Unspent Transaction Output, it will then send out the 5BTC from Y and send you back 4BTC.</p>

<p>In this case, you may see 2 inputs on the input side.</p>

<p>Your logic may not work because the "fromAddress" for the 10BTC might be the fromAddress that you hold, but the fromAddress for the BTC, you may not have.</p>

<p><em>In order to find out all transactions from personA to personB, you must know all of their public addresses in their wallet.</em></p>

<p>You also cannot assume that all inputs, are from personA because with BTC you can pool transactions, so each input can be from another person.</p>

<p>If you had all of the addresses, your code would look something like this:</p>

<pre><code>if fromAddresses.contains(row['addr']):
</code></pre>

<p>Hope that helps.</p>

CC BY-SA 3.0
2018-01-16T14:30:02.777Z
2018-01-16T14:30:02.777Z
Kyle Graham
<p>Each bitcoin transaction can have multiple previous transactions as inputs and multiple new scriptPubKeys as destinations so it's a many-to-many relationship. </p>

<p>Your logic should still work to detect when an address you are interested in has made a spend. You could end up with duplicate output addresses if an address you're matching is used multiple times in the inputs of a single transaction.</p>

<p><strong>Update</strong>: As per Pieter Wuille's comment there can also be multiple addresses referenced in a single transaction's scriptPubKey. Typically this would be when the OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY operations are used.</p>

<p>In that case your script would either not work or would potentially miss some matches since row['addr'] needs to supply a list of multiple bitcoin addresses.</p>

CC BY-SA 3.0
2017-09-17T00:50:28.273Z
I believe this does not answer OP's question, which is about multiple addresses within one transaction input.
Pieter Wuille
CC BY-SA 3.0
2017-09-14T11:37:07.383Z
2017-09-18T03:44:04.687Z
2017-09-18T03:44:04.687Z
sipsorcery
<p>I need to find out all the bitcoins transferred from a particular address to a particular address. </p>

<p>For this I am using the <a href="https://blockexplorer.com/api-ref" rel="nofollow noreferrer">blockexplorer API</a>, for this I use their "Transactions for multiple addresses" API since only this provides a paginated response. Others only give 10 results by default. </p>

<p>So I iterate through transactions, look <code>fromAddress</code> in <code>vin</code>, similarly search for <code>toAddress</code> in <code>vout</code>. If all satisfied I take that value. </p>

<pre><code>for transaction in txs:
  valueIn = transaction['valueIn']
  valueOut = transaction['valueOut']
  confirmations = transaction['confirmations']
  if confirmations &gt;= 12:
    vin = transaction['vin']
  for row in vin:
      if row['addr'] == fromAddress:
        vout = transaction['vout']
        for j in vout:
          addresses = j['scriptPubKey']['addresses']
          if toAddress in set(addresses):
            output.append(j['value'])
</code></pre>

<p>But in some case I saw multiple addresses in <code>vin</code>, when is that? 
Would my logic would still be right, if my address is part of that?</p>

<transactions><bitcoin-core-development><sendtoaddress>
When does `vin` contain multiple addresses
garg10may
# When does `vin` contain multiple addresses

(Asked by: username_0 on 2017-09-14)

I need to find out all the bitcoins transferred from a particular address to a particular address.

For this I am using the [blockexplorer API](https://blockexplorer.com/api-ref), for this I use their "Transactions for multiple addresses" API since only this provides a paginated response. Others only give 10 results by default.

So I iterate through transactions, look `fromAddress` in `vin`, similarly search for `toAddress` in `vout`. If all satisfied I take that value.

```
for transaction in txs:
  valueIn = transaction['valueIn']
  valueOut = transaction['valueOut']
  confirmations = transaction['confirmations']
  if confirmations >= 12:
    vin = transaction['vin']
  for row in vin:
      if row['addr'] == fromAddress:
        vout = transaction['vout']
        for j in vout:
          addresses = j['scriptPubKey']['addresses']
          if toAddress in set(addresses):
            output.append(j['value'])

```

But in some case I saw multiple addresses in `vin`, when is that?
Would my logic would still be right, if my address is part of that?

**Tags:** transactions, bitcoin-core-development, sendtoaddress


---

## 2 answers

### Answer by username_1 on 2018-01-16. Score: 1

So a transaction will have multiple vins, if it takes multiple UTXOs to send the value.

So let's say you in the past have received 10BTC from X, and 5BTC from Y.

You now need to send 11BTC to Kate.

What it will do is,

it will send out the 10BTC from X, as this is an Unspent Transaction Output, it will then send out the 5BTC from Y and send you back 4BTC.

In this case, you may see 2 inputs on the input side.

Your logic may not work because the "fromAddress" for the 10BTC might be the fromAddress that you hold, but the fromAddress for the BTC, you may not have.

*In order to find out all transactions from personA to personB, you must know all of their public addresses in their wallet.*

You also cannot assume that all inputs, are from personA because with BTC you can pool transactions, so each input can be from another person.

If you had all of the addresses, your code would look something like this:

```
if fromAddresses.contains(row['addr']):

```

Hope that helps.


---

### Answer by username_2 on 2017-09-14. Score: 0

Each bitcoin transaction can have multiple previous transactions as inputs and multiple new scriptPubKeys as destinations so it's a many-to-many relationship.

Your logic should still work to detect when an address you are interested in has made a spend. You could end up with duplicate output addresses if an address you're matching is used multiple times in the inputs of a single transaction.

**Update**: As per username_3 username_3's comment there can also be multiple addresses referenced in a single transaction's scriptPubKey. Typically this would be when the OP\_CHECKMULTISIG or OP\_CHECKMULTISIGVERIFY operations are used.

In that case your script would either not work or would potentially miss some matches since row['addr'] needs to supply a list of multiple bitcoin addresses.

> **Comments:**
> **username_3**: I believe this does not answer OP's question, which is about multiple addresses within one transaction input.  

---

