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?

  • 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... Nov 2, 2017 at 8:19
  • 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
    Nov 2, 2017 at 12:02
  • 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? Nov 2, 2017 at 14:43
  • 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
    Nov 3, 2017 at 21:15
  • 1
    have you solved this puzzle?
    – lzl124631x
    Oct 4, 2018 at 6:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.