Using Blockstream's api to broadcast a raw transaction to the Bitcoin testnet, I encountered the following error:

sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 64)"}

I've noticed that many people have ran into a similar issue before. However, all of the proposed solutions didn't fix my issue. I've looked at the Bitcoin source code on Github and determined that the data I am committing to my hash for signing is incorrect.

Below is the hash pre-image that I'm creating for bip143 p2sh(p2wpkh).

    nVersion:     01000000
    hashPrevouts: 4f3c0f6726ec7f020da2a01598d1741225ea429a34bfdd4c4af2a1c9e45a9bed
    hashSequence: 3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044
    outpoint:     b9d615615976600739be12a67f326836e4256d7d1c4fe50163536ad8dd7647c301000000
    scriptCode:   1976a91499f27cf1ecb8c1a4c20bdbcdc7992cdb12c9ee5d88ac
    amount:       6981680000000000
    nSequence:    ffffffff
    hashOutputs:  57dbf9cb180c89fe35000b693ea089e521097e6d3f504cfec1620325fcec0036
    nLockTime:    00000000
    nHashType:    01000000

1 Answer 1


After a while of debugging, I was able to find the issue.

My previous assumption that I was committing the wrong data to the hash was correct.

The transaction ID that is needed to construct hashPrevouts and outpoint was incorrect. I needed to reverse the bytes of this value for the hash to be correct.

For example:

  • b9d615615976600739be12a67f326836e4256d7d1c4fe50163536ad8dd7647c3 (a searchable txid on Bitcoin testnet)


  • c34776ddd86a536301e54f1c7d6d25e43668327fa612be39076076596115d6b9.

In summary, my advice would be to step through the interpreter and reevaluate your assumptions of all the data that you're committing to the hash for signing.

A little bit of code never hurts,

Typescript: Buffer.from(transactionId, "hex").reverse().toString("hex");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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