<p>Note that Bitcoin transactions don't actually contain the txid or hash within them. This is only part of the decoding output from Bitcoin Core.</p>

<p>The <code>hash</code> is there because of segwit. Segwit specifies that witness data for a segwit input (i.e. signatures, scripts) are not part of the txid. Those are in a separate area in the transaction. You can see this information decoded in the <code>txinwitness</code> field. So the hash is over the entire transaction, including this witness data, but the txid is not. Since transactions that do not have any segwit inputs do not have witness fields for their inputs, the <code>txid</code> and <code>hash</code> are the same.</p>

CC BY-SA 4.0
2019-07-19T01:53:13.480Z
thank you - that makes sense regarding the hash field.  But if txid is not included in the transaction, is it also not included in the vin/vout fields within a transaction?
d3wannabe
CC BY-SA 4.0
2019-07-19T01:55:31.460Z
No, the txids for the outputs being spent are included. Just the txid of the transaction itself is not since you can calculate the txid from it.
Ava Chow
CC BY-SA 4.0
2019-07-19T01:46:23.040Z
2019-07-19T01:46:23.040Z
Ava Chow
<p>Using bitcoin-cli decoderawtransaction I see results like...</p>

<pre><code>{
  "txid": "d2183b3ea763f41a30ec5ba6fbf6e5f32e0ca6a5e8761249c533fe22190f71f1",
  "hash": "d2183b3ea763f41a30ec5ba6fbf6e5f32e0ca6a5e8761249c533fe22190f71f1",
  "version": 2,
  "size": 225,
  "vsize": 225,
   etc...
</code></pre>

<p>Why is the "hash" field necessary if the txid field is already a hash? (more specifically a double-pass through SHA-256 of the transaction's data)</p>

<p>I'm noticing in some transactions that txid and hash are equal, but in others they're not.  Appreciate any explanation on the difference since I'm struggling to figure it out through Google and the source code comments.</p>

<transactions><json-rpc><bitcoin-cli>
Why is the field 'hash' necessary in a bitcoin transaction?
d3wannabe
# Why is the field 'hash' necessary in a bitcoin transaction?

(Asked by: username_0 on 2019-07-19)

Using bitcoin-cli decoderawtransaction I see results like...

```
{
  "txid": "d2183b3ea763f41a30ec5ba6fbf6e5f32e0ca6a5e8761249c533fe22190f71f1",
  "hash": "d2183b3ea763f41a30ec5ba6fbf6e5f32e0ca6a5e8761249c533fe22190f71f1",
  "version": 2,
  "size": 225,
  "vsize": 225,
   etc...

```

Why is the "hash" field necessary if the txid field is already a hash? (more specifically a double-pass through SHA-256 of the transaction's data)

I'm noticing in some transactions that txid and hash are equal, but in others they're not. Appreciate any explanation on the difference since I'm struggling to figure it out through Google and the source code comments.

**Tags:** transactions, json-rpc, bitcoin-cli


---

## 1 answers

### Answer by username_1 on 2019-07-19. Score: 5 | Accepted answer

Note that Bitcoin transactions don't actually contain the txid or hash within them. This is only part of the decoding output from Bitcoin Core.

The `hash` is there because of segwit. Segwit specifies that witness data for a segwit input (i.e. signatures, scripts) are not part of the txid. Those are in a separate area in the transaction. You can see this information decoded in the `txinwitness` field. So the hash is over the entire transaction, including this witness data, but the txid is not. Since transactions that do not have any segwit inputs do not have witness fields for their inputs, the `txid` and `hash` are the same.

> **Comments:**
> **username_0**: thank you - that makes sense regarding the hash field.  But if txid is not included in the transaction, is it also not included in the vin/vout fields within a transaction?  
> **username_1**: No, the txids for the outputs being spent are included. Just the txid of the transaction itself is not since you can calculate the txid from it.  

---

