I want to test if a script or is standard or not. Is it possible with Bitcoin Core's RPC?


The top-level type parameter of the decodescript RPC can tell you if a scriptPubKey is standard. For example:

bitcoin-cli decodescript deadbeef
  "type": "nonstandard",
  "p2sh": "3PbdV4zdrjtFD4fyYebGR4oxeatrSzb2d1",
  "segwit": {
    "asm": "0 5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953",
    "hex": "00205f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953",
    "reqSigs": 1,
    "type": "witness_v0_scripthash",
    "addresses": [
    "p2sh-segwit": "37CpdZEgXUB7LS7rvTLsYopRifDf76eZrZ"

However, I don't know of a way to test whether a P2SH/segwit redeem script is standard using the RPC. If, instead, you want to know whether or not a particular spend would be accepted to your node's memory pool, Bitcoin Core's development branch (master) features a new testmempoolaccept RPC; here's it's current help:

testmempoolaccept ["rawtxs"] ( allowhighfees )

Returns if raw transaction (serialized, hex-encoded) would be accepted by mempool.

This checks if the transaction violates the consensus or policy rules.

See sendrawtransaction call.

1. ["rawtxs"]       (array, required) An array of hex strings of raw transactions.
                                        Length must be one for now.                                                                                                           2. allowhighfees    (boolean, optional, default=false) Allow high fees

[                   (array) The result of the mempool acceptance test for each raw transaction in the input array.
                            Length is exactly one for now.
  "txid"           (string) The transaction hash in hex
  "allowed"        (boolean) If the mempool allows this tx to be inserted
  "reject-reason"  (string) Rejection string (only present when 'allowed' is false)


Create a transaction
> bitcoin-cli createrawtransaction "[{\"txid\" : \"mytxid\",\"vout\":0}]" "{\"myaddress\":0.01}"
Sign the transaction, and get back the hex
> bitcoin-cli signrawtransaction "myhex"

Test acceptance of the transaction (signed hex)
> bitcoin-cli testmempoolaccept "signedhex"

You could also test out the complete script using regtest. By default regtest has the standardness checks disabled, by you can re-enable them by starting bitcoind with the -acceptnonstdtxn=0 parameter.


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.