3

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.

1 Answer 1

3

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.

4
  • Thanks for taking the time to respond with such a helpful answer, and so quickly, Pieter. You're absolutely indispensable.
    – satirn
    Nov 27, 2021 at 19:15
  • 1
    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
    Nov 27, 2021 at 19:21
  • I was doing the same thing as @satirn, I thought validaterawtransaction was a more intuitive name also.
    – greatwolf
    Feb 2, 2023 at 4:35
  • 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
    Feb 2, 2023 at 4:39

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .