Why can’t a node find a Bitcoin output that hasn’t been spent on-chain?

Bitcoin Core’s gettxout query for an unspent output also considers the local mempool by default. If the mempool already contains a pending transaction that spends the output, it won’t appear in the default query results. If you query only the on-chain state instead, the same output may still be found until the pending spend is included in a block.

For example, a BTC output has been confirmed as received. Later, the wallet submits a transaction that spends it. A node has accepted the transaction, but it has not yet been included in a block. If you query only the confirmed chain, the original output will still appear unspent. If you include the mempool in the query, the node has already seen a pending spend, so it will exclude the output from the unspent results.

When troubleshooting, query using both settings with the same node, transaction hash, and output index. If a result appears when checking the chain alone but not when the mempool is included, further check for local unconfirmed spends. If both queries return nothing, also consider causes such as the output having already been spent on-chain or the index being incorrect. An empty result alone cannot tell you which situation applies.

This article explains Bitcoin Core’s query semantics and is intended for technical discussion only.

$BTC #Bitcoin

Original documentation: https://bitcoincore.org/en/doc/30.0.0/rpc/blockchain/gettxout/