1

I am scanning the bitcoin blocks and looking for transactions that involve my list of addresses. This is more like a wallet hosting service. I need the "From" and "To" addresses used in the transaction.

I am using the "bitcoin-cli gettransaction" method to get transaction details.

I know that VIN block should contain the sender addresses and VOUT block should be the receiving addresses. I can see the VOUT block with receiving addresses, but I can't see the "From" addresses in VIN block.

How can I get the "from" and "To" address in bitcoin transaction?

Here is a data sample,

     "vin": [
    {
      "txid": "c5355fe45f785f14f15b3e41894e21083978e9e78ed23b7a3a00f0061ec735a5",
      "vout": 1,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "3045022100f5ee5cb40a06419c55eb2de549ee97daf77a8e2588d3e0dd800cade7605d4c760220453533f8ba09165076f4a252dc9336f2d4040a3b071754441805c94df555a5ce01",
        "02f6e670a3fcb90b40bb66fa550b5202ae8c9b50d69fcc1ffb5377b022f7f629fd"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 0.00309202,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 2f8f5127a4f8234552e6ab2107303d1761e6ddbe OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9142f8f5127a4f8234552e6ab2107303d1761e6ddbe88ac",
        "address": "15LUSrgQ1qFtgx5237AskkjeMcX4bpHfBH",
        "type": "pubkeyhash"
      }
    },
    {
      "value": 0.06857278,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 83e6911dcb2f412677376c6a70a01655dd534457",
        "hex": "001483e6911dcb2f412677376c6a70a01655dd534457",
        "address": "bc1qs0nfz8wt9aqjvaehd348pgqk2hw4x3zhupv0xw",
        "type": "witness_v0_keyhash"
      }
    }
  ]

RedGrittyBrick
  • 26,841
  • 3
  • 25
  • 51

1 Answers1

1

Transaction inputs are listed via the txid and the outputs index. In the case of your example, you'd need to make a second call:

bitcoin-cli gettransaction c5355fe45f785f14f15b3e41894e21083978e9e78ed23b7a3a00f0061ec735a5

And then look at the output at the index n: 1 to find the address in question.

chytrik
  • 18,170
  • 3
  • 19
  • 48
  • 1
    Thank you ! You can see this transaction here https://www.blockchain.com/btc/tx/2c33baf70886d48cc3259ca1dc5d3dde974394f476d5faa2673cb6e35721fd83 . . The problem is that I am unable to see the "from address" in my output. I can make a second call to the txid in VIN, but I am trying to avoid that. The output is the receiver address. It has the other 2 addresses. 1 address is the actual receiver and the second address should be where it returns the remaining balance – Abdul Rehman Rajput Feb 10 '22 at 11:21
  • error message: No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)

    Why do you need a wallet to get info about transactions that do NOT include addresses you own?

    If you have a wallet, then the error message is Invalid or non-wallet transaction id. So this answer is expected to wor for your transactions only.

    – Putnik Sep 12 '23 at 19:05
  • @Putnik if you have txindex=1 set then you can query any transaction, otherwise it would indeed work for your wallet's transactions only. – chytrik Sep 13 '23 at 23:31
  • I do have txindex=1 and all 800k+ blocks are on my disk. Maybe, something else? – Putnik Sep 14 '23 at 11:41
  • @Putnik it would be best to open a new question, rather than discuss this in the comments of a somewhat unrelated question. – chytrik Sep 15 '23 at 18:31