<p>Since <a href="https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki" rel="nofollow noreferrer">BIP144</a>, transaction data consists of two parts (normal data and witness data). There are also two distinct transaction serialization formats:</p>
<ul>
<li>The legacy serialization format, which stores version number, transaction inputs, transaction outputs, and locktime.</li>
<li>The extended serialization format, which also has a flag/marker to indicate the extended format is in use, and has witness data for every transaction input.</li>
</ul>
<p>The extended format must be used if witness data is present. The legacy format must be used if no witness data is present.</p>
<p>The <strong>txid</strong> is the double-SHA256 hash of the serialized transaction <em>in legacy format</em>, meaning that any witness data has to be stripped out (as the legacy format does not support witness data). If the transaction had no witness data in the first place (as pre-segwit transaction do), the txid is just the hash of the serialized transaction.</p>
<p>The <strong>hash</strong> (or wtxid) of a transaction is the double-SHA256 hash of the serialization <em>including potential witness data</em>. If the transaction contains no witness data, this is identical to the txid.</p>

CC BY-SA 4.0
2023-03-04T20:34:56.857Z
Pieter Wuille, Thanks for your knowledge. But now which on of them (txid or wtxid) is used for merkle root ?  (Which is on output of getrawmempool when transaction is on mempool)
Ali
CC BY-SA 4.0
2023-03-04T20:38:24.610Z
Both. The **txid** is included in the normal Merkle tree (whose root is in the block header). The **wtxid**s are also included in another Merkle tree (whose root is included in the coinbase transaction output in an OP_RETURN; see BIP141).
Pieter Wuille
CC BY-SA 4.0
2023-03-04T14:16:23.817Z
2023-03-14T05:46:00.023Z
2023-03-14T05:46:00.023Z
Pieter Wuille
<p>What is the relationship between <strong>transaction data</strong> and <strong>transaction id</strong> (which is used at mempool to generate Merkle root)?</p>
<p>Note : when we query the <strong>getblock</strong> with <strong>verbosity 2</strong>, we get <strong>raw block</strong> in <strong>json</strong> format. at the transactions part, each transaction have 3 suspicious part :</p>
<ol>
<li><strong>txid</strong> (transaction id)</li>
<li><strong>hash</strong></li>
<li><strong>hex</strong> (which is raw transaction in hex string format)</li>
</ol>
<p>I am looking for a relatio between these three parameters.</p>

<transactions><block><raw-transaction><daemon><getrawtransaction>
Relation between transaction data and transaction id
Ali
# Relation between transaction data and transaction id

(Asked by: username_0 on 2023-03-04)

What is the relationship between **transaction data** and **transaction id** (which is used at mempool to generate Merkle root)?

Note : when we query the **getblock** with **verbosity 2**, we get **raw block** in **json** format. at the transactions part, each transaction have 3 suspicious part :

1. **txid** (transaction id)
2. **hash**
3. **hex** (which is raw transaction in hex string format)

I am looking for a relatio between these three parameters.

**Tags:** transactions, block, raw-transaction, daemon, getrawtransaction


---

## 1 answers

### Answer by username_1 on 2023-03-04. Score: 7 | Accepted answer

Since [BIP144](https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki), transaction data consists of two parts (normal data and witness data). There are also two distinct transaction serialization formats:

* The legacy serialization format, which stores version number, transaction inputs, transaction outputs, and locktime.
* The extended serialization format, which also has a flag/marker to indicate the extended format is in use, and has witness data for every transaction input.

The extended format must be used if witness data is present. The legacy format must be used if no witness data is present.

The **txid** is the double-SHA256 hash of the serialized transaction *in legacy format*, meaning that any witness data has to be stripped out (as the legacy format does not support witness data). If the transaction had no witness data in the first place (as pre-segwit transaction do), the txid is just the hash of the serialized transaction.

The **hash** (or wtxid) of a transaction is the double-SHA256 hash of the serialization *including potential witness data*. If the transaction contains no witness data, this is identical to the txid.

> **Comments:**
> **username_0**: username_1 username_1, Thanks for your knowledge. But now which on of them (txid or wtxid) is used for merkle root ?  (Which is on output of getrawmempool when transaction is on mempool)  
> **username_1**: Both. The **txid** is included in the normal Merkle tree (whose root is in the block header). The **wtxid**s are also included in another Merkle tree (whose root is included in the coinbase transaction output in an OP_RETURN; see BIP141).  

---

