1

How do you find the transaction whose input, vin, is a given output, vout? For example, the following is the JSON representation of the block with height 1000; here the mining reward is locked behind the given scriptPubKey, and I am interested in finding a transaction where this output is referenced as input.

{
    "hash": "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09",
    "confirmations": 716370,
    "height": 1000,
    "version": 1,
    "versionHex": "00000001",
    "merkleroot": "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
    "time": 1232346882,
    "mediantime": 1232344831,
    "nonce": 2595206198,
    "bits": "1d00ffff",
    "difficulty": 1,
    "chainwork": "000000000000000000000000000000000000000000000000000003e903e903e9",
    "nTx": 1,
    "previousblockhash": "0000000008e647742775a230787d66fdf92c46a48c896bfbc85cdc8acc67e87d",
    "nextblockhash": "00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6",
    "strippedsize": 216,
    "size": 216,
    "weight": 864,
    "tx": [
        {
            "txid": "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
            "hash": "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
            "version": 1,
            "size": 135,
            "vsize": 135,
            "weight": 540,
            "locktime": 0,
            "vin": [
                {
                    "coinbase": "04ffff001d02fd04",
                    "sequence": 4294967295
                }
            ],
            "vout": [
                {
                    "value": 50.00000000,
                    "n": 0,
                    "scriptPubKey": {
                        "asm": "04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG",
                        "hex": "4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac",
                        "type": "pubkey"
                    }
                }
            ],
            "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d02fd04ffffffff0100f2052a01000000434104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac00000000"
        }
    ]
}

1 Answer 1

1

This information is not stored by Bitcoin Core. Outputs are stored until they are spent, and then removed from the UTXO database. There is no information inside a transaction that indicates where it was spent (in the future), so you would manually have to compile this information yourself by iterating over all transactions in the blockchain.

2
  • Can't we use the index of transactions created when using the -txindex=1 argument? Iterating through all blocks/transactions is possible but a very expensive operation, leveraging index to some extent could prune some of the processes at least. Commented Jan 6, 2022 at 21:22
  • I don't think txindex=1 would help in this case. I suggest building your own database while parsing which you can make more complicated queries to, like block explorers do. Commented Jan 6, 2022 at 21:32

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.