<p>The RPC you're looking for is <code>testmempoolaccept</code>. It checks whether a raw transaction would be accepted into the local mempool, without actually doing so. Only transactions that satisfy all consensus rules, plus various policy rules, are accepted into the mempool.</p>
<blockquote>
<p>Am I correct in stating that the <code>sendrawtransaction</code> RPC method first validates a transaction before attempting to broadcast the transaction to the network.</p>
</blockquote>
<p>Yes, broadcasting invalid transactions would be simultaneously bad for privacy, and risk being banned by your peer nodes.</p>

CC BY-SA 4.0
2021-11-27T19:15:55.780Z
Thanks for taking the time to respond with such a helpful answer, and so quickly, Pieter. You're absolutely indispensable.
satirn
CC BY-SA 4.0
2021-11-27T19:21:53.327Z
What is the rationale behind naming the method `testmempoolaccept`? I immediately searched for a `validaterawtransaction` method in the RPC docs, then since there was none, I did a cmd+f for validate which obviously didn't help either. It seems more intuitive for it to be named `validaterawtransaction`/`validatetransaction` though I appreciate `testmempoolaccept` is slightly more descriptive.
satirn
CC BY-SA 4.0
2023-02-02T04:35:48.840Z
I was doing the same thing as @satirn, I thought `validaterawtransaction` was a more intuitive name also.
greatwolf
CC BY-SA 4.0
2023-02-02T04:39:38.003Z
I'm assuming `testmempoolaccept` also considers whether the spending inputs is in the valid utxo set. If so is there a way to also exclude that check in `testmempoolaccept` or some other command? For example, you want to check if a pre-signed transaction is valid but the input funds being spent haven't been committed yet.
greatwolf
CC BY-SA 4.0
2021-11-27T19:09:02.690Z
2021-11-27T19:09:02.690Z
Pieter Wuille
<p>I would like to check the validity of a raw transaction (i.e. whether it would be accepted by network nodes), without broadcasting the transaction to the network. I am interested in knowing what is the best way to achieve this 1) using Bitcoin Core's RPC API 2) by any other means (e.g. open source tool).</p>
<p>Am I correct in stating that the <code>sendrawtransaction</code> RPC method first validates a transaction before attempting to broadcast the transaction to the network?</p>
<p>Edit - I'm aware that the <code>decoderawtransaction</code> method can be used to manually/visually assess the details of a transaction, but I'd like to be 100% sure that the transaction signatures and parameters are correct without having to actually broadcast the transaction.</p>

<bitcoin-core><json-rpc><raw-transaction><mempool><validation>
Validate raw transaction hex without broadcasting
satirn
# Validate raw transaction hex without broadcasting

(Asked by: username_0 on 2021-11-27)

I would like to check the validity of a raw transaction (i.e. whether it would be accepted by network nodes), without broadcasting the transaction to the network. I am interested in knowing what is the best way to achieve this 1) using Bitcoin Core's RPC API 2) by any other means (e.g. open source tool).

Am I correct in stating that the `sendrawtransaction` RPC method first validates a transaction before attempting to broadcast the transaction to the network?

Edit - I'm aware that the `decoderawtransaction` method can be used to manually/visually assess the details of a transaction, but I'd like to be 100% sure that the transaction signatures and parameters are correct without having to actually broadcast the transaction.

**Tags:** bitcoin-core, json-rpc, raw-transaction, mempool, validation


---

## 1 answers

### Answer by username_1 on 2021-11-27. Score: 3 | Accepted answer

The RPC you're looking for is `testmempoolaccept`. It checks whether a raw transaction would be accepted into the local mempool, without actually doing so. Only transactions that satisfy all consensus rules, plus various policy rules, are accepted into the mempool.

> Am I correct in stating that the `sendrawtransaction` RPC method first validates a transaction before attempting to broadcast the transaction to the network.

Yes, broadcasting invalid transactions would be simultaneously bad for privacy, and risk being banned by your peer nodes.

> **Comments:**
> **username_0**: Thanks for taking the time to respond with such a helpful answer, and so quickly, Pieter. You're absolutely indispensable.  
> **username_0**: What is the rationale behind naming the method `testmempoolaccept`? I immediately searched for a `validaterawtransaction` method in the RPC docs, then since there was none, I did a cmd+f for validate which obviously didn't help either. It seems more intuitive for it to be named `validaterawtransaction`/`validatetransaction` though I appreciate `testmempoolaccept` is slightly more descriptive.  
> **username_2**: I was doing the same thing as @username_0, I thought `validaterawtransaction` was a more intuitive name also.  
> **username_2**: I'm assuming `testmempoolaccept` also considers whether the spending inputs is in the valid utxo set. If so is there a way to also exclude that check in `testmempoolaccept` or some other command? For example, you want to check if a pre-signed transaction is valid but the input funds being spent haven't been committed yet.  

---

