2

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.

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.

2
  • Thanks for taking the time to respond with such a helpful answer, and so quickly, Pieter. You're absolutely indispensable.
    – satirn
    Nov 27 '21 at 19:15
  • 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 '21 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.