Summary: The difference is when the tx is a segwit tx, the calculation of
hash does not include the witness data, whereas the
The definition of transaction hash remains the same as txid for non-witness transactions (non Segwit). The reason the mainnet tx has a different hash than the txid is because it is a witness transaction. If you run
bitcoin-cli help getrawtransaction it will show you:
Result (if verbose is set to true):
"txid" : "id", (string) The transaction id (same as provided)
"hash" : "id", (string) The transaction hash (differs from txid for witness transactions)
The following is from BIP 141.
Note that the BIP states, "signature data is no longer part of the transaction hash."
A new data structure,
witness, is defined. Each transaction will have 2 IDs.
txid remains unchanged: the double SHA256 of the traditional serialization format:
wtxid is defined: the double SHA256 of the new serialization with witness data:
nLockTime are same as traditional serialization.
marker MUST be a 1-byte zero value:
flag MUST be a 1-byte non-zero value. Currently,
0x01 MUST be used.
witness is a serialization of all witness data of the transaction. Each txin is associated with a witness field. A witness field starts with a
var_int to indicate the number of stack items for the txin. It is followed by stack items, with each item starts with a
var_int to indicate the length. Witness data is NOT script.
A non-witness program (defined hereinafter) txin MUST be associated with an empty witness field, represented by a
0x00. If all txins are not witness program, a transaction's
wtxid is equal to its