<p>I suspect there is no good way to do it.
However is there any sub-optimal way to find the transaction that spends a transaction output (knowing the <code>txid</code> and <code>index</code>) with Bitcoin RPC?<br>
Assuming <code>txindex=1</code> and <code>prune=0</code>.  </p>

<p>This was the more general question. In my case: </p>

<ol>
<li>When I receive the TXO, it's actually an UTXO.  </li>
<li>I am only interested in confirmed transactions.</li>
</ol>

<p>The only way I can come up with to answer both questions is iterating through all the transactions of all the blocks from the TXO's block to the last received block and the mempool. Or in my case, I don't mind the mempool.<br>
Nevertheless this is cumbersome and likely I'd be better off with some kind of indexer. Is there better way to do it with RPC?</p>

CC BY-SA 3.0
2017-11-02T08:19:18.253Z
not sure on the question, when you have your tx ID, then you can list the tx details with "bitcoin-cli getrawtransaction". I don't see if you want to search all transactions in blockchain (then you don't need a tx ID), or if you have a tx ID and search for details of it...
pebwindkraft
CC BY-SA 3.0
2017-11-02T12:02:21.460Z
I implicitly implied `getrawtransaction` in my sub-optimal solution. It doesn't tell you which tx spends the txos of the transaction, but it tells you which block contains the transaction.
nopara73
CC BY-SA 3.0
2017-11-02T14:43:22.043Z
sure? I think it does not show the block. The "vin[]" structure contains a link to the previous tx ID, and the previous tx vout number. I wonder what you mean by txo of "the" transaction. I am not aware of an identifier for a transaction output. In a tx we have usually the vin[] structure, from where to move Satoshis, and a vout[] structure, where the Satoshis shall go to. Can you perhaps rephrase with vin, vout, or previous transaction, previous input?  So we can better follow your idea?
pebwindkraft
CC BY-SA 3.0
2017-11-03T21:15:23.860Z
1) Yes, it shows the block. 2) While there is no identifier for the transaction output, the spender transaction identifies it with a `txid`-`index` pair. My point is, if I have a transaction, then based on the `vin[]` one can track all transaction down backwards all the way to the coinbase, since `vin[]` has previous outputs (`txid`-`index` pairs). While the reverse does not work: from the `vout[]` I cannot go forward, since `vout[]` is `amount`-`scriptPubKey` pairs.
nopara73
CC BY-SA 3.0
2017-11-03T22:28:43.260Z
ah, ok, got it. I am not aware on an easy solution. You would have to take a vout[], decompose the scriptPubKey and it's address, search for this address in the blockchain (or a block explorer) within the time frame of the tx (or block height), take this tx number, take the vout[], decompose...   This is tough work, basically your own block explorer. What comes to my mind is this: what happens when a bitcoin tumbler, a cross chain tx, or an exchange comes into the game - then the tracks with their attributes loose their meaning... but certainly a funny experience...
pebwindkraft
CC BY-SA 4.0
2018-10-04T06:58:40.130Z
have you solved this puzzle?
lzl124631x
CC BY-SA 4.0
2018-10-04T15:35:17.180Z
You can't with Bitcoin Core. I hacked around by parsing the whole chain and build an index table for my specific purpose, (I don't need mempool, nor non-bech32 addresses) which makes things much faster (only a few weeks to build this intex table) so I doubt it'd be useful to you, but here's the code: https://github.com/zkSNACKs/WalletWasabi/blob/master/WalletWasabi/Services/IndexBuilderService.cs
You can do it with libbitcoin though. At the end of this presentation I asked questions regarding it and the presenter discusses the pros and cons: https://www.youtube.com/watch?v=QtB4YUneiEE
nopara73
CC BY-SA 4.0
2024-03-25T20:46:51.820Z
on blockchain.info you can get the spending transaction with: `spending_outpoints.tx_index` on `https://blockchain.info/tx/$tx_index_or_txid?format=json`
Ciro Santilli OurBigBook.com
<transactions><json-rpc><utxo><txindex>
Bitcoin RPC: How to find the transaction that spends a TXO?
nopara73
# Bitcoin RPC: How to find the transaction that spends a TXO?

(Asked by: username_0 on 2017-11-02)

I suspect there is no good way to do it.
However is there any sub-optimal way to find the transaction that spends a transaction output (knowing the `txid` and `index`) with Bitcoin RPC?  
Assuming `txindex=1` and `prune=0`.

This was the more general question. In my case:

1. When I receive the TXO, it's actually an UTXO.
2. I am only interested in confirmed transactions.

The only way I can come up with to answer both questions is iterating through all the transactions of all the blocks from the TXO's block to the last received block and the mempool. Or in my case, I don't mind the mempool.  
Nevertheless this is cumbersome and likely I'd be better off with some kind of indexer. Is there better way to do it with RPC?

**Tags:** transactions, json-rpc, utxo, txindex

> **Comments:**
> **username_1**: not sure on the question, when you have your tx ID, then you can list the tx details with "bitcoin-cli getrawtransaction". I don't see if you want to search all transactions in blockchain (then you don't need a tx ID), or if you have a tx ID and search for details of it...  
> **username_0**: I implicitly implied `getrawtransaction` in my sub-optimal solution. It doesn't tell you which tx spends the txos of the transaction, but it tells you which block contains the transaction.  
> **username_1**: sure? I think it does not show the block. The "vin[]" structure contains a link to the previous tx ID, and the previous tx vout number. I wonder what you mean by txo of "the" transaction. I am not aware of an identifier for a transaction output. In a tx we have usually the vin[] structure, from where to move Satoshis, and a vout[] structure, where the Satoshis shall go to. Can you perhaps rephrase with vin, vout, or previous transaction, previous input?  So we can better follow your idea?  
> **username_0**: 1) Yes, it shows the block. 2) While there is no identifier for the transaction output, the spender transaction identifies it with a `txid`-`index` pair. My point is, if I have a transaction, then based on the `vin[]` one can track all transaction down backwards all the way to the coinbase, since `vin[]` has previous outputs (`txid`-`index` pairs). While the reverse does not work: from the `vout[]` I cannot go forward, since `vout[]` is `amount`-`scriptPubKey` pairs.  
> **username_1**: ah, ok, got it. I am not aware on an easy solution. You would have to take a vout[], decompose the scriptPubKey and it's address, search for this address in the blockchain (or a block explorer) within the time frame of the tx (or block height), take this tx number, take the vout[], decompose...   This is tough work, basically your own block explorer. What comes to my mind is this: what happens when a bitcoin tumbler, a cross chain tx, or an exchange comes into the game - then the tracks with their attributes loose their meaning... but certainly a funny experience...  
> **username_2**: have you solved this puzzle?  
> **username_0**: You can't with Bitcoin Core. I hacked around by parsing the whole chain and build an index table for my specific purpose, (I don't need mempool, nor non-bech32 addresses) which makes things much faster (only a few weeks to build this intex table) so I doubt it'd be useful to you, but here's the code: https://github.com/zkSNACKs/WalletWasabi/blob/master/WalletWasabi/Services/IndexBuilderService.cs You can do it with libbitcoin though. At the end of this presentation I asked questions regarding it and the presenter discusses the pros and cons: https://www.youtube.com/watch?v=QtB4YUneiEE  
> **username_3**: on blockchain.info you can get the spending transaction with: `spending_outpoints.tx_index` on `https://blockchain.info/tx/$tx_index_or_txid?format=json`  

---

## 0 answers

