<p>I am trying to create a raw TX and sign it. I know that to sign a transaction we need the message hash (here m) value which is double sha256 hash of something like this:</p>
<pre><code>01000000 #Version
01 #Number of Input
be66e10da854e7aea9338c1f91cd489768d1d6d7189f586d7a3613f2a24d5396 #reverse hash of txid 
00000000 #Number of output to create
19 76 a9 14 dd6cce9f255a8cc17bda8ba0373df8e861cb866e 88 ac #Placeholder for purpose of signing, the scriptPub of output
ffffffff #sequence
01 #output to create
23ce010000000000 #Value to send (output val - fees)
19 76 a9 14 a2fd2e039a86dbcf0e1a664729e09e8007f89510 88 ac #address to which we are sending 
00000000 #Lock time
01000000 #Hash code
</code></pre>
<p>Together they can be written as:</p>
<pre><code>0100000001be66e10da854e7aea9338c1f91cd489768d1d6d7189f586d7a3613f2a24d5396000000001976a914dd6cce9f255a8cc17bda8ba0373df8e861cb866e88acffffffff0123ce0100000000001976a914a2fd2e039a86dbcf0e1a664729e09e8007f8951088ac0000000001000000
</code></pre>
<p>Now after double hashing them the value I am getting is:</p>
<pre><code>8cce3b8b2ab5644d4ab4d5c13be06608c18631fc46c0866000e67dca98d3f6bb
</code></pre>
<p>While the value should be:</p>
<pre><code>1cde0239b55717cca8003104abc2ec2673d4f6fabea0b74351940e382e88486f
</code></pre>
<p>To calculate has I have used <a href="https://www.webdevtutor.net/tools/online-hash-generator-sha256d" rel="nofollow noreferrer">this calculator</a></p>
<p>Please help me what is wrong here.
Thanks</p>

CC BY-SA 4.0
2023-07-13T09:15:52.620Z
Does this answer your question? [How are TXIDs determined from the raw hex data of a block? Also, what is the coinbase transaction?](https://bitcoin.stackexchange.com/questions/114118/how-are-txids-determined-from-the-raw-hex-data-of-a-block-also-what-is-the-coi) -- note where and why I use `hex.Decode` in my answer there.
RedGrittyBrick
CC BY-SA 4.0
2023-07-13T10:10:19.357Z
@RedGrittyBrick Nope I am asking how to calculate double sha256 hash of message to get the digest using which a TX is signed. I am encountering an error in getting correct hash.
madhurkant
CC BY-SA 4.0
2023-07-13T13:38:24.803Z
I took my [example code](https://go.dev/play/p/PDURm9NTLYm) from [my answer](https://bitcoin.stackexchange.com/a/114121/13866) to [the other question](https://bitcoin.stackexchange.com/questions/114118/how-are-txids-determined-from-the-raw-hex-data-of-a-block-also-what-is-the-coi) and plugged in your Tx Hex and expected hash and **[my example code with your tx hex](https://go.dev/play/p/GfeT8gBnp7O) produced the result you expected**. So *I still very much believe the answers to the other question also answer this one*.
RedGrittyBrick
CC BY-SA 4.0
2023-07-13T13:48:24.653Z
Moreover, I get your exact incorrect result 8c...bb if I don't do the hex.Decode I explicitly mentioned in my comment and if I also don't reverse the result for Endianness.
RedGrittyBrick
<hash><raw-transaction><message-signing>
How to hash a message (tx message) to get message hash?
madhurkant
# How to hash a message (tx message) to get message hash?

(Asked by: username_0 on 2023-07-13)

I am trying to create a raw TX and sign it. I know that to sign a transaction we need the message hash (here m) value which is double sha256 hash of something like this:

```
01000000 #Version
01 #Number of Input
be66e10da854e7aea9338c1f91cd489768d1d6d7189f586d7a3613f2a24d5396 #reverse hash of txid 
00000000 #Number of output to create
19 76 a9 14 dd6cce9f255a8cc17bda8ba0373df8e861cb866e 88 ac #Placeholder for purpose of signing, the scriptPub of output
ffffffff #sequence
01 #output to create
23ce010000000000 #Value to send (output val - fees)
19 76 a9 14 a2fd2e039a86dbcf0e1a664729e09e8007f89510 88 ac #address to which we are sending 
00000000 #Lock time
01000000 #Hash code

```

Together they can be written as:

```
0100000001be66e10da854e7aea9338c1f91cd489768d1d6d7189f586d7a3613f2a24d5396000000001976a914dd6cce9f255a8cc17bda8ba0373df8e861cb866e88acffffffff0123ce0100000000001976a914a2fd2e039a86dbcf0e1a664729e09e8007f8951088ac0000000001000000

```

Now after double hashing them the value I am getting is:

```
8cce3b8b2ab5644d4ab4d5c13be06608c18631fc46c0866000e67dca98d3f6bb

```

While the value should be:

```
1cde0239b55717cca8003104abc2ec2673d4f6fabea0b74351940e382e88486f

```

To calculate has I have used [this calculator](https://www.webdevtutor.net/tools/online-hash-generator-sha256d)

Please help me what is wrong here.
Thanks

**Tags:** hash, raw-transaction, message-signing

> **Comments:**
> **username_1**: Does this answer your question? [How are TXIDs determined from the raw hex data of a block? Also, what is the coinbase transaction?](https://bitcoin.stackexchange.com/questions/114118/how-are-txids-determined-from-the-raw-hex-data-of-a-block-also-what-is-the-coi) -- note where and why I use `hex.Decode` in my answer there.  
> **username_0**: @username_1 Nope I am asking how to calculate double sha256 hash of message to get the digest using which a TX is signed. I am encountering an error in getting correct hash.  
> **username_1**: I took my [example code](https://go.dev/play/p/PDURm9NTLYm) from [my answer](https://bitcoin.stackexchange.com/a/114121/13866) to [the other question](https://bitcoin.stackexchange.com/questions/114118/how-are-txids-determined-from-the-raw-hex-data-of-a-block-also-what-is-the-coi) and plugged in your Tx Hex and expected hash and **[my example code with your tx hex](https://go.dev/play/p/GfeT8gBnp7O) produced the result you expected**. So *I still very much believe the answers to the other question also answer this one*.  
> **username_1**: Moreover, I get your exact incorrect result 8c...bb if I don't do the hex.Decode I explicitly mentioned in my comment and if I also don't reverse the result for Endianness.  

---

## 0 answers

