<p>Using a wallet would allow you to do this, whether you choose to use BDK or Bitcoin Core's watchonly wallet. But since you are only interested in mempool transactions spending a specific output you can use the RPC command <code>gettxspendingprevout</code>:</p>
<blockquote>
<pre><code>gettxspendingprevout [{&quot;txid&quot;:&quot;hex&quot;,&quot;vout&quot;:n},...]

Scans the mempool to find transactions spending any of the given
outputs

Arguments:
1. outputs                 (json array, required) The transaction outputs that we want to check, and within each, the txid (string) vout
(numeric).
     [
       {                   (json object)
         &quot;txid&quot;: &quot;hex&quot;,    (string, required) The transaction id
         &quot;vout&quot;: n,        (numeric, required) The output number
       },
       ...
     ]

Result: [                      (json array)   
  {                              (json object)
      &quot;txid&quot; : &quot;hex&quot;,            (string) the transaction id of the checked output
      &quot;vout&quot; : n,                (numeric) the vout value of the checked output
      &quot;spendingtxid&quot; : &quot;hex&quot;     (string, optional) the transaction id of the mempool transaction spending this output (omitted if unspent)  
  },
  ...
]
</code></pre>
</blockquote>

CC BY-SA 4.0
2024-07-16T09:16:13.053Z
2024-07-16T09:16:13.053Z
Antoine Poinsot
<p>I try to concurrently monitor a bunch of signed but non published transactions. I want to detect asap if any of the inputs into these bond transactions have been used in another transaction in my mempool. Available for use is the bitcoin core rpc and bdk/rust bitcoin. IIUC testmempoolaccept only detects if the inputs already have been confirmed in another TX.</p>
<p>The straightforward way i can think of is calling getrawmempool and then getmempoolentry on each transaction, iterating trough the inputs. This can get heavy for a larger mempool.</p>
<p>My question is if there is another possible way to do this in a more (time) efficient manner using either the core rpc or functionality of bdk/rust bitcoin/another rust crate?</p>

<bitcoin-core><json-rpc><utxo><mempool><rust-bitcoin>
Most efficient way to check if utxos are consumed in mempool txs using core rpc and rust
f321x
# Most efficient way to check if utxos are consumed in mempool txs using core rpc and rust

(Asked by: username_0 on 2024-07-16)

I try to concurrently monitor a bunch of signed but non published transactions. I want to detect asap if any of the inputs into these bond transactions have been used in another transaction in my mempool. Available for use is the bitcoin core rpc and bdk/rust bitcoin. IIUC testmempoolaccept only detects if the inputs already have been confirmed in another TX.

The straightforward way i can think of is calling getrawmempool and then getmempoolentry on each transaction, iterating trough the inputs. This can get heavy for a larger mempool.

My question is if there is another possible way to do this in a more (time) efficient manner using either the core rpc or functionality of bdk/rust bitcoin/another rust crate?

**Tags:** bitcoin-core, json-rpc, utxo, mempool, rust-bitcoin


---

## 1 answers

### Answer by username_1 on 2024-07-16. Score: 3 | Accepted answer

Using a wallet would allow you to do this, whether you choose to use BDK or Bitcoin Core's watchonly wallet. But since you are only interested in mempool transactions spending a specific output you can use the RPC command `gettxspendingprevout`:

> ```
> gettxspendingprevout [{"txid":"hex","vout":n},...]
>
> Scans the mempool to find transactions spending any of the given
> outputs
>
> Arguments:
> 1. outputs                 (json array, required) The transaction outputs that we want to check, and within each, the txid (string) vout
> (numeric).
>      [
>        {                   (json object)
>          "txid": "hex",    (string, required) The transaction id
>          "vout": n,        (numeric, required) The output number
>        },
>        ...
>      ]
>
> Result: [                      (json array)   
>   {                              (json object)
>       "txid" : "hex",            (string) the transaction id of the checked output
>       "vout" : n,                (numeric) the vout value of the checked output
>       "spendingtxid" : "hex"     (string, optional) the transaction id of the mempool transaction spending this output (omitted if unspent)  
>   },
>   ...
> ]
>
> ```


---

