0

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, 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?

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.

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

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.

  • I believe this does not answer OP's question, which is about multiple addresses within one transaction input. – Pieter Wuille Sep 17 '17 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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