What you will learn
A Bitcoin output can be unspent in the confirmed chain and already spent by a transaction in your node's mempool. Bitcoin Core's <code>gettxout</code> RPC lets you inspect that distinction with its <code>include_mempool</code> argument.
This guide creates one confirmed output on a private regtest chain, spends that exact outpoint, and asks the node about it three times. Before the spend, the output appears. While the spending transaction is unconfirmed, <code>gettxout</code> returns <code>null</code> when the mempool is included and still returns the confirmed output when the mempool is excluded. After the spend is mined, both queries return <code>null</code>.
The exercise uses only synthetic regtest coins. It never connects to mainnet, handles real funds, imports a secret, or contacts another node. The commands target Bitcoin Core 32.1, the latest published release on 30 November 2026. The behavior is documented in the Bitcoin Core 32.0 RPC reference, and the private chain follows the project's regtest example.
Prerequisites
You need Bitcoin Core 32.1 with wallet support, Bash, <code>jq</code>, about 200 MB of free space, and no running process using the temporary data directory chosen below.
Verify the installed release:
bitcoind --version
bitcoin-cli --version
The first line should identify Bitcoin Core Daemon version <code>v32.1</code>. If it reports another version, read that version's RPC help before continuing:
bitcoin-cli help gettxout
bitcoin-cli help createrawtransaction
bitcoin-cli help signrawtransactionwithwallet
This workspace did not contain a Bitcoin Core binary. The complete RPC sequence below was reviewed against the official 32.0 RPC documentation but was not executed here. Run it only in the disposable regtest directory described below.
1. Start an isolated regtest node
Choose a new directory and start Bitcoin Core without peer discovery:
export LAB="$HOME/bitcoin-regtest-utxo-lab"
mkdir -p "$LAB"
bitcoind \
-regtest \
-datadir="$LAB" \
-connect=0 \
-fallbackfee=0.0002 \
-daemon
Create a wallet named <code>lab</code> and define a command array that always points at this node and wallet:
bitcoin-cli -regtest -datadir="$LAB" -rpcwait createwallet lab
CLI=(bitcoin-cli -regtest -datadir="$LAB" -rpcwallet=lab)
"${CLI[@]}" getblockchaininfo | jq '{chain, blocks}'
Expected result:
{
"chain": "regtest",
"blocks": 0
}
Stop if <code>chain</code> is anything other than <code>regtest</code>. The <code>-connect=0</code> option prevents automatic outbound peer connections. The node still exposes RPC locally, so do not reuse a directory or configuration containing production credentials.
2. Mine spendable regtest coins
Create a mining address and generate 101 blocks:
MINE_ADDRESS=$("${CLI[@]}" getnewaddress "mining")
"${CLI[@]}" generatetoaddress 101 "$MINE_ADDRESS" >/dev/null
"${CLI[@]}" getbalance
The balance should show <code>50.00000000</code> BTC. These are regtest coins with no market value. The first block reward becomes spendable after the next 100 blocks, which is why the fixture mines 101.
Create a receiving address, send it exactly 1 regtest BTC, and locate the matching output index:
RECEIVE_ADDRESS=$("${CLI[@]}" getnewaddress "fixture")
FUND_TXID=$("${CLI[@]}" sendtoaddress "$RECEIVE_ADDRESS" 1.0)
FUND_TX=$("${CLI[@]}" getrawtransaction "$FUND_TXID" true)
FUND_VOUT=$(jq -r \
--arg address "$RECEIVE_ADDRESS" \
'.vout[] | select(.scriptPubKey.address == $address) | .n' \
<<<"$FUND_TX")
printf 'funding outpoint: %s:%s\n' "$FUND_TXID" "$FUND_VOUT"
<code>FUND_VOUT</code> must be one integer. If it is empty or prints multiple lines, stop and inspect <code>FUND_TX</code> rather than guessing an index.
Mine the funding transaction:
"${CLI[@]}" generatetoaddress 1 "$MINE_ADDRESS" >/dev/null
3. Confirm that the output exists
Query the outpoint with and without the mempool view:
"${CLI[@]}" gettxout "$FUND_TXID" "$FUND_VOUT" true
"${CLI[@]}" gettxout "$FUND_TXID" "$FUND_VOUT" false
Both calls should return an object containing <code>confirmations</code>, <code>value</code>, <code>scriptPubKey</code>, and <code>coinbase</code>. The value should be <code>1.00000000</code>, and <code>coinbase</code> should be <code>false</code>.
At this point the mempool has no transaction spending the fixture output. Including or excluding it therefore produces the same UTXO answer.
4. Spend that exact outpoint
Create one destination and a raw transaction that spends the 1 BTC output. The new output is 0.9999 BTC, leaving a 0.0001 BTC fee:
NEXT_ADDRESS=$("${CLI[@]}" getnewaddress "destination")
RAW=$("${CLI[@]}" createrawtransaction \
"[{\"txid\":\"$FUND_TXID\",\"vout\":$FUND_VOUT}]" \
"{\"$NEXT_ADDRESS\":0.9999}")
SIGNED=$("${CLI[@]}" signrawtransactionwithwallet "$RAW")
jq -e '.complete == true' <<<"$SIGNED" >/dev/null
SPEND_TXID=$("${CLI[@]}" sendrawtransaction "$(jq -r '.hex' <<<"$SIGNED")")
printf 'mempool spend: %s\n' "$SPEND_TXID"
"${CLI[@]}" getmempoolentry "$SPEND_TXID" \
| jq '{vsize, weight, fees, depends, spentby}'
The signing result must say <code>complete: true</code>. The mempool query should return an object for <code>SPEND_TXID</code>. If <code>sendrawtransaction</code> rejects the transaction, keep the error and inspect the input amount, output amount, signature result, and current UTXO state. Do not raise the fee by changing random values.
5. Compare the two node views
Ask <code>gettxout</code> about the original outpoint again:
WITH_MEMPOOL=$("${CLI[@]}" gettxout "$FUND_TXID" "$FUND_VOUT" true)
CHAIN_ONLY=$("${CLI[@]}" gettxout "$FUND_TXID" "$FUND_VOUT" false)
printf 'with mempool: %s\n' "$WITH_MEMPOOL"
printf 'chain only: %s\n' "$CHAIN_ONLY"
Expected result before mining the spend:
with mempool: null
chain only: { ... "value": 1.00000000 ... }
This is the central result. The chain-only UTXO set still contains the confirmed output. The node's combined chain and mempool view treats it as unavailable because <code>SPEND_TXID</code> already spends it.
<code>null</code> does not prove that an output never existed. It means the output was not found in the selected view. The txid may be wrong, the vout may be wrong, the transaction may be unknown to the node, or the output may already be spent.
6. Confirm the spend and query again
Mine one block:
"${CLI[@]}" generatetoaddress 1 "$MINE_ADDRESS" >/dev/null
"${CLI[@]}" gettxout "$FUND_TXID" "$FUND_VOUT" true
"${CLI[@]}" gettxout "$FUND_TXID" "$FUND_VOUT" false
Both calls should now return:
null
The spend has moved from the mempool into the confirmed chain. Excluding the mempool no longer changes the answer because the confirmed UTXO set itself records the output as spent.
Stop the disposable node:
bitcoin-cli -regtest -datadir="$LAB" stop
Wait for the process to exit before removing the lab directory. Confirm that <code>LAB</code> points to the disposable path you created. Never delete a Bitcoin data directory by pattern or by copying a cleanup command without checking the expanded path.
Troubleshooting
<code>gettxout</code> returns <code>null</code> before the spend
Check the outpoint first:
printf '%s:%s\n' "$FUND_TXID" "$FUND_VOUT"
"${CLI[@]}" getrawtransaction "$FUND_TXID" true | jq '.vout'
Make sure the funding transaction was mined, the vout belongs to <code>RECEIVE_ADDRESS</code>, and the command is talking to the same regtest data directory.
<code>signrawtransactionwithwallet</code> is incomplete
The <code>lab</code> wallet must own the funding output. Check the address and wallet selection. Do not paste a private key into the command. Restart the fixture with an address generated by the same disposable wallet.
<code>sendrawtransaction</code> reports a missing or spent input
Query both UTXO views and the mempool before trying again. A previous run may already have broadcast the spend. Do not broadcast a second transaction blindly.
The result differs on another Bitcoin Core release
Use <code>bitcoin-cli help gettxout</code> from that binary and check its release documentation. The guide was reviewed for Bitcoin Core 32.1 using the 32.0 RPC reference. It does not claim compatibility with forks or older releases.
Limits
The fixture demonstrates one node's local view. It does not prove that another node has accepted the spending transaction, that miners will confirm it, or that the transaction cannot be replaced or evicted. <code>gettxout</code> is an inspection RPC, not a payment finality signal.
The commands were not executed in this hosted workspace because Bitcoin Core was unavailable. The shell structure, JSON arguments, output selection, and expected <code>gettxout</code> state transitions were checked against Bitcoin Core's published release, RPC reference, and regtest examples. No mainnet node, wallet, credentials, secrets, peers, or real funds were used.
