<p>Bitcoin Cash uses <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki" rel="nofollow noreferrer">BIP 143</a> for signature hash creation.</p>

<p>From the BIP:</p>

<blockquote>
<pre><code>  Double SHA256 of the serialization of:
     1. nVersion of the transaction (4-byte little endian)
     2. hashPrevouts (32-byte hash)
     3. hashSequence (32-byte hash)
     4. outpoint (32-byte hash + 4-byte little endian) 
     5. scriptCode of the input (serialized as scripts inside CTxOuts)
     6. value of the output spent by this input (8-byte little endian)
     7. nSequence of the input (4-byte little endian)
     8. hashOutputs (32-byte hash)
     9. nLocktime of the transaction (4-byte little endian)
    10. sighash type of the signature (4-byte little endian)
</code></pre>
</blockquote>

<p>So the hash preimage will look like this:</p>

<pre><code>01000000be16f25831b40c713fed6627e39aa7717170f5cdd62c765bd4882abbefdaa50e3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d77000000001976a914ac599afa005a522e376334c6727e3c0f1aa6398688ac20a1070000000000ffffffffc8e2e71fe663fc91d7aa109feffee0f1497862af35525f68f500cbd55f6ed6620000000041000000
</code></pre>

<p>And here is its breakdown:</p>

<pre><code>nVersion: 01000000
hashPrevouts: be16f25831b40c713fed6627e39aa7717170f5cdd62c765bd4882abbefdaa50e
hashSequence: 3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044
outpoint: fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d7700000000
scriptCode: 1976a914ac599afa005a522e376334c6727e3c0f1aa6398688ac
value: 20a1070000000000
nSequence: ffffffff
hashOutputs: c8e2e71fe663fc91d7aa109feffee0f1497862af35525f68f500cbd55f6ed662
nLocktime: 00000000
sighash: 41000000
</code></pre>

CC BY-SA 3.0
2018-02-23T09:33:42.803Z
I get the "hashPrevouts" to be:
"be16f25831b40c713fed6627e39aa7717170f5cdd62c765bd4882abbefdaa50e" which is sha256d("fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d7700000000").



Who of us is right?
Thorkil Værge
CC BY-SA 3.0
2018-02-23T15:54:35.340Z
Hmm, yes, you're right. I will edit the answer
Ava Chow
CC BY-SA 3.0
2018-02-28T21:26:45.880Z
What exactly does this value of the sighash field mean?
Thorkil Værge
CC BY-SA 3.0
2018-02-28T22:14:00.513Z
Sighash indicates what data exactly is being signed. It's a type indicator.
Ava Chow
CC BY-SA 3.0
2018-02-23T03:53:50.440Z
2018-02-23T15:54:58.677Z
2018-02-23T15:54:58.677Z
Ava Chow
<p>I am attempting to manually generate a signed transaction which is to be sent from my address <code>1GiJZtN7wjUuL4V5i7ZYYDAvFtqi5AhCDr</code> which is <code>bitcoincash:qzk9nxh6qpd9yt3hvv6vvun78s834f3escdhu2vdjp</code> in the new address format. I am using an uncompressed public key in this transaction.</p>

<p>I have the following unsigned Bitcoin Cash transaction. How do I find its hash preimage which is the hash used in the signing of this transaction?</p>

<blockquote>
  <p>0100000001fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d770000000000ffffffff0100a00700000000001976a914a8e181e0847b495df439066ca8fb36ce093692be88ac00000000</p>
</blockquote>

<p>Breaking it up, it looks like this:</p>

<p><code>01000000</code> - nVersion</p>

<p><code>01</code> - num of inputs</p>

<p><code>fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d77</code> - txid (little-endian)</p>

<p><code>00000000</code> - vout</p>

<p><code>00</code> - size of sigScript</p>

<p><code>ffffffff</code> - sequence number</p>

<p><code>01</code> - num of outputs</p>

<p><code>00a0070000000000</code> - amount (hex, little-endian)</p>

<p><code>1976a914a8e181e0847b495df439066ca8fb36ce093692be88ac</code> - scriptPubKey</p>

<p><code>00000000</code> - timeLock</p>

<p>I am attempting to consume output 0 from the transaction with txid: <code>776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb</code>,
The scriptPubKey for that transaction's output 0 is:</p>

<pre><code>1976a914ac599afa005a522e376334c6727e3c0f1aa6398688ac
</code></pre>

<p>The value of the received output is 0.005 BCH</p>

<p>The transaction I am attempting to consume can be found here:
<a href="https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb.rawhex" rel="nofollow noreferrer">https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb</a>
And the rawtx for the transaction I want to consume is here:
<a href="https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb" rel="nofollow noreferrer">https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb.rawhex</a></p>

<p>Can anybody help me?</p>

<bitcoin-cash><hash><signature><bip143>
How do I generate the Bitcoin Cash hash preimage?
Thorkil Værge
# How do I generate the Bitcoin Cash hash preimage?

(Asked by: username_0 on 2018-02-22)

I am attempting to manually generate a signed transaction which is to be sent from my address `1GiJZtN7wjUuL4V5i7ZYYDAvFtqi5AhCDr` which is `bitcoincash:qzk9nxh6qpd9yt3hvv6vvun78s834f3escdhu2vdjp` in the new address format. I am using an uncompressed public key in this transaction.

I have the following unsigned Bitcoin Cash transaction. How do I find its hash preimage which is the hash used in the signing of this transaction?

> 0100000001fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d770000000000ffffffff0100a00700000000001976a914a8e181e0847b495df439066ca8fb36ce093692be88ac00000000

Breaking it up, it looks like this:

`01000000` - nVersion

`01` - num of inputs

`fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d77` - txid (little-endian)

`00000000` - vout

`00` - size of sigScript

`ffffffff` - sequence number

`01` - num of outputs

`00a0070000000000` - amount (hex, little-endian)

`1976a914a8e181e0847b495df439066ca8fb36ce093692be88ac` - scriptPubKey

`00000000` - timeLock

I am attempting to consume output 0 from the transaction with txid: `776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb`,
The scriptPubKey for that transaction's output 0 is:

```
1976a914ac599afa005a522e376334c6727e3c0f1aa6398688ac

```

The value of the received output is 0.005 BCH

The transaction I am attempting to consume can be found here:
[https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb](https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb.rawhex)
And the rawtx for the transaction I want to consume is here:
[https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb.rawhex](https://bch.btc.com/776da96a8df767c519ca08330f49e7e34e1331f027e1fb321f31c57a5c8e4afb)

Can anybody help me?

**Tags:** bitcoin-cash, hash, signature, bip143


---

## 1 answers

### Answer by username_1 on 2018-02-23. Score: 4 | Accepted answer

Bitcoin Cash uses [BIP 143](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki) for signature hash creation.

From the BIP:

> ```
>   Double SHA256 of the serialization of:
>      1. nVersion of the transaction (4-byte little endian)
>      2. hashPrevouts (32-byte hash)
>      3. hashSequence (32-byte hash)
>      4. outpoint (32-byte hash + 4-byte little endian) 
>      5. scriptCode of the input (serialized as scripts inside CTxOuts)
>      6. value of the output spent by this input (8-byte little endian)
>      7. nSequence of the input (4-byte little endian)
>      8. hashOutputs (32-byte hash)
>      9. nLocktime of the transaction (4-byte little endian)
>     10. sighash type of the signature (4-byte little endian)
>
> ```

So the hash preimage will look like this:

```
01000000be16f25831b40c713fed6627e39aa7717170f5cdd62c765bd4882abbefdaa50e3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d77000000001976a914ac599afa005a522e376334c6727e3c0f1aa6398688ac20a1070000000000ffffffffc8e2e71fe663fc91d7aa109feffee0f1497862af35525f68f500cbd55f6ed6620000000041000000

```

And here is its breakdown:

```
nVersion: 01000000
hashPrevouts: be16f25831b40c713fed6627e39aa7717170f5cdd62c765bd4882abbefdaa50e
hashSequence: 3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044
outpoint: fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d7700000000
scriptCode: 1976a914ac599afa005a522e376334c6727e3c0f1aa6398688ac
value: 20a1070000000000
nSequence: ffffffff
hashOutputs: c8e2e71fe663fc91d7aa109feffee0f1497862af35525f68f500cbd55f6ed662
nLocktime: 00000000
sighash: 41000000

```

> **Comments:**
> **username_0**: I get the "hashPrevouts" to be: "be16f25831b40c713fed6627e39aa7717170f5cdd62c765bd4882abbefdaa50e" which is sha256d("fb4a8e5c7ac5311f32fbe127f031134ee3e7490f3308ca19c567f78d6aa96d7700000000").    Who of us is right?  
> **username_1**: Hmm, yes, you're right. I will edit the answer  
> **username_0**: What exactly does this value of the sighash field mean?  
> **username_1**: Sighash indicates what data exactly is being signed. It's a type indicator.  

---

