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

CC BY-SA 4.0
2022-01-06T21:22:29.550Z
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.
Dr. Strangelove
CC BY-SA 4.0
2022-01-06T21:32:42.827Z
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.
meshcollider
CC BY-SA 4.0
2022-01-06T07:39:07.897Z
2022-01-06T07:39:07.897Z
meshcollider
<p>How do you find the transaction whose input, <code>vin</code>, is a given output, <code>vout</code>? For example, the following is the JSON representation of the block with height <code>1000</code>; here the mining reward is locked behind the given <code>scriptPubKey</code>, and I am interested in finding a transaction where this output is referenced as input.</p>
<pre><code>{
    &quot;hash&quot;: &quot;00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09&quot;,
    &quot;confirmations&quot;: 716370,
    &quot;height&quot;: 1000,
    &quot;version&quot;: 1,
    &quot;versionHex&quot;: &quot;00000001&quot;,
    &quot;merkleroot&quot;: &quot;fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33&quot;,
    &quot;time&quot;: 1232346882,
    &quot;mediantime&quot;: 1232344831,
    &quot;nonce&quot;: 2595206198,
    &quot;bits&quot;: &quot;1d00ffff&quot;,
    &quot;difficulty&quot;: 1,
    &quot;chainwork&quot;: &quot;000000000000000000000000000000000000000000000000000003e903e903e9&quot;,
    &quot;nTx&quot;: 1,
    &quot;previousblockhash&quot;: &quot;0000000008e647742775a230787d66fdf92c46a48c896bfbc85cdc8acc67e87d&quot;,
    &quot;nextblockhash&quot;: &quot;00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6&quot;,
    &quot;strippedsize&quot;: 216,
    &quot;size&quot;: 216,
    &quot;weight&quot;: 864,
    &quot;tx&quot;: [
        {
            &quot;txid&quot;: &quot;fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33&quot;,
            &quot;hash&quot;: &quot;fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33&quot;,
            &quot;version&quot;: 1,
            &quot;size&quot;: 135,
            &quot;vsize&quot;: 135,
            &quot;weight&quot;: 540,
            &quot;locktime&quot;: 0,
            &quot;vin&quot;: [
                {
                    &quot;coinbase&quot;: &quot;04ffff001d02fd04&quot;,
                    &quot;sequence&quot;: 4294967295
                }
            ],
            &quot;vout&quot;: [
                {
                    &quot;value&quot;: 50.00000000,
                    &quot;n&quot;: 0,
                    &quot;scriptPubKey&quot;: {
                        &quot;asm&quot;: &quot;04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG&quot;,
                        &quot;hex&quot;: &quot;4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac&quot;,
                        &quot;type&quot;: &quot;pubkey&quot;
                    }
                }
            ],
            &quot;hex&quot;: &quot;01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d02fd04ffffffff0100f2052a01000000434104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac00000000&quot;
        }
    ]
}
</code></pre>

<transaction-input><traceability><spending>
Track the expenditure of an output with Bitcoin-qt via the REST API
Dr. Strangelove
# Track the expenditure of an output with Bitcoin-qt via the REST API

(Asked by: username_0 on 2022-01-06)

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

```

**Tags:** transaction-input, traceability, spending


---

## 1 answers

### Answer by username_1 on 2022-01-06. Score: 1 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  
> **username_1**: 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.  

---

