How can I know the address that sent the BTC?

2.3k Views Asked by At

I made a transaction with bitcoind. I sent money from address A to address B.

At the client which holds the address B, when I issue "gettransaction" passing the transaction id, it shows information like the type (which is receive), the address which received, and the amount. But it does not tell where the BTC came from.

How can I know which address sent the BTC?

Side question: If I sent BTC back to this address, will it work like a "devolution"? (Which is my objective here)

1

There are 1 best solutions below

1
On

From Bitcoin stackexchange, (pseudo-code)

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])
}