<p><strong>Summary:</strong> The difference is when the tx is a segwit tx, the calculation of <code>hash</code> does not include the witness data, whereas the <code>txid</code> does.</p>

<p>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 <code>bitcoin-cli help getrawtransaction</code> it will show you:</p>

<pre><code>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)
  ...
</code></pre>

<h2>Segregated Witness</h2>

<p>The following is from <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" rel="noreferrer">BIP 141</a>.</p>

<p>Note that the BIP states, "signature data is no longer part of the transaction hash."</p>

<h3>Transaction ID</h3>

<p>A new data structure, <code>witness</code>, is defined. Each transaction will have 2 IDs.</p>

<p>Definition of <code>txid</code> remains unchanged: the double SHA256 of the traditional serialization format:</p>

<pre><code>[nVersion][txins][txouts][nLockTime]
</code></pre>

<p>A new <code>wtxid</code> is defined: the double SHA256 of the new serialization with witness data:</p>

<pre><code>[nVersion][marker][flag][txins][txouts][witness][nLockTime]
</code></pre>

<p>Format of <code>nVersion</code>, <code>txins</code>, <code>txouts</code>, and <code>nLockTime</code> are same as traditional serialization.</p>

<p>The <code>marker</code> MUST be a 1-byte zero value: <code>0x00</code>.</p>

<p>The <code>flag</code> MUST be a 1-byte non-zero value. Currently, <code>0x01</code> MUST be used.</p>

<p>The <code>witness</code> is a serialization of all witness data of the transaction. Each txin is associated with a witness field. A witness field starts with a <code>var_int</code> to indicate the number of stack items for the txin. It is followed by stack items, with each item starts with a <code>var_int</code> to indicate the length. Witness data is NOT script.</p>

<p>A non-witness program (defined hereinafter) txin MUST be associated with an empty witness field, represented by a <code>0x00</code>. If all txins are not witness program, a transaction's <code>wtxid</code> is equal to its <code>txid</code>. </p>

CC BY-SA 4.0
2018-07-28T19:17:34.037Z
2019-02-19T15:12:08.357Z
2019-02-19T15:12:08.357Z
JBaczuk
<p>Sometimes the <strong>txid</strong> key is the same as the <strong>hash</strong> key in the return of getrawtransaction, sometimes different. I'm trying to understand more about these...</p>

<p>What are the differences, and why are they sometimes identical and sometimes different?</p>

<p><strong>Example - identical in this testnet tx:</strong></p>

<p>bitcoin-cli -testnet getrawtransaction c3f11d1708ac20eff9137d4eadd62dd99d71ce22dc51bc51d4e5b83958d9596d 1</p>

<p><strong>Example - different in this livenet tx:</strong></p>

<p>bitcoin-cli getrawtransaction df2fd78e42590f301b5174e7d6665887380ad1f49a4688a0f8adffa0829855cc 1</p>

<bitcoind>
Whats the difference between "txid" and "hash" - getrawtransaction bitcoind
sizzlecookie
# Whats the difference between "txid" and "hash" - getrawtransaction bitcoind

(Asked by: username_0 on 2018-07-28)

Sometimes the **txid** key is the same as the **hash** key in the return of getrawtransaction, sometimes different. I'm trying to understand more about these...

What are the differences, and why are they sometimes identical and sometimes different?

**Example - identical in this testnet tx:**

bitcoin-cli -testnet getrawtransaction c3f11d1708ac20eff9137d4eadd62dd99d71ce22dc51bc51d4e5b83958d9596d 1

**Example - different in this livenet tx:**

bitcoin-cli getrawtransaction df2fd78e42590f301b5174e7d6665887380ad1f49a4688a0f8adffa0829855cc 1

**Tags:** bitcoind


---

## 1 answers

### Answer by username_1 on 2018-07-28. Score: 9 | Accepted answer

**Summary:** The difference is when the tx is a segwit tx, the calculation of `hash` does not include the witness data, whereas the `txid` does.

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)
  ...

```

## Segregated Witness

The following is from [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki).

Note that the BIP states, "signature data is no longer part of the transaction hash."

### Transaction ID

A new data structure, `witness`, is defined. Each transaction will have 2 IDs.

Definition of `txid` remains unchanged: the double SHA256 of the traditional serialization format:

```
[nVersion][txins][txouts][nLockTime]

```

A new `wtxid` is defined: the double SHA256 of the new serialization with witness data:

```
[nVersion][marker][flag][txins][txouts][witness][nLockTime]

```

Format of `nVersion`, `txins`, `txouts`, and `nLockTime` are same as traditional serialization.

The `marker` MUST be a 1-byte zero value: `0x00`.

The `flag` MUST be a 1-byte non-zero value. Currently, `0x01` MUST be used.

The `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 `txid`.


---

