I am able to get the tx id (or transaction hash) of almost any transaction but the one where the script starts with an "OP_O" (which is, I think, the null dummy introduced here https://github.com/bitcoin/bitcoin/pull/3843)

For example:


How am I suppose to get the txid of this transaction? And how is it different from a regular (without multisig) one?

1 Answer 1


How am I suppose to get the txid of this transaction?

The same way you get the txid of any other transaction, by hashing it (unless it is segwit). Note that the transaction you linked to is not a segwit transaction, so you can just take its hash.

If the transaction is a segwit transaction (as indicated by the marker and flag bytes of 0x0001 following the version bytes), then you need to only hash the parts that are non-segwit. Specifically, you drop all of the segwit parts (so the marker and flag and any witnesses which can be found between the last output and the locktime), and hash what is left. This is described in BIP 144.

And how is it different from a regular (without multisig) one?

There isn't.

  • 1
    Thank you, I will double-check my code. I tested it on a full block (about 2k txs) and the only times the txid didn't match (20 times) was when a "OP_0" appeared in one of the inputs scripts.
    – Kevin P
    Oct 24, 2018 at 18:07
  • Also, I don't simply hash the transaction as it is. I parse it, store all its elements in a data structure, and then append them back and hash them (I use the tx id as an error check).
    – Kevin P
    Oct 24, 2018 at 18:11
  • OP_0 is used in segwit transactions too, so that may be your problem.
    – Ava Chow
    Oct 24, 2018 at 19:30
  • Problem solved: I had a problem with my "varint" function... Thank you!
    – Kevin P
    Oct 25, 2018 at 6:29
  • FWIW, got the same symptom in 2022 but from a different underlying problem. OP_PUSHDATA1 failed to encode its opcode, 0x4c, in the transaction. Obviously, the same problem occured with OP_PUSHDATA2 and OP_PUSHDATA4.
    – RooSoft
    Nov 25, 2022 at 13:49

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.