13

How do I find out which addresses are the inputs of a given transaction, given its transaction ID? I know there is a way, as satoshidice.com uses this. I would like to do this with own software and not rely on some third party provider, which could easily kill their service.

EDIT:

Basically I'm creating a PHP project, where I need to find out when a new transaction arrives and which address sent it. So I need a way to get a notification or start a PHP script (called with needed variables [txid, sender address, receiving address, value]) when a new transaction arrives.

1
  • I edited your question to tidy up the grammar and spelling, but also fixed the assumption that there is a single "sender" address. It's quite possible that the transaction has multiple inputs and multiple outputs, so there's no single "sender". SatoshiDICE doesn't care; it just sends the winnings to one of the sending addresses. Commented Jun 5, 2012 at 10:41

2 Answers 2

10

I just answered a similar question. The relevant parts are:

It is now possible to determine the list of addresses that sent a transaction using the raw transaction JSON-RPC API calls that were released with bitcoind and bitcoin-qt version 0.7. The pseudo-code to accomplish this is:

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])
}
4
  • Trying to find out the same thing, your "decoderawtransaction(getrawtransaction(input['txid']))" instruction failed at first. However, the problem fixed itself and your example worked after I waited for raw_tx['confirmation'] and raw_tx['blockhash'] to be defined.
    – adamrmcd
    Commented Jun 3, 2013 at 3:44
  • this basically scans through the blockchain for the output transaction corresponding to the hash value in the later input-transaction. is there not a way of getting the answer using the input scriptsig though? Commented Mar 25, 2014 at 2:17
  • Asked a question related to your pseudocode. Would appreciate if you can take a look. Commented Dec 29, 2017 at 8:37
  • Note that if your wallet did not sent the previous transaction, you will need to enable txindex=1 in bitcoin.conf to track non-wallet transactions. Otherwise, the call to getrawtransaction will fail
    – Ron
    Commented Mar 4, 2022 at 1:03
2

The Bitcoin.org client doesn't provide this.

I believe your options are:

1
  • i thought about using ABE but i were told uses about 1,4GB of ram, which is just to much for my "small" vps with 2GB of ram in total. Are the other more "lightweight" ? Commented Jun 5, 2012 at 10:11

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.