user82868: I am trying to construct a raw transaction for bitcoin cash testnet. I have made a lot of use out of this very nice answer to how to construct a raw transaction, but am still unable to construct a correct one myself. I would like to spend the the first output 7098b2735336c85077e9704cb8ba521f5c2d92f768081345c5ded26c52fcc1a9.
Here is what I do:

Create a transaction using the previous transaction hash and index with the scriptSig filled in with the scriptPubKey of the output I want to redeem. The raw transaction looks like this:
01000000
01
a9c1fc526cd2dec545130868f7922d5c1f52bab84c70e97750c8365373b29870
00000000
19
76a914edc822bff914a255b819156c70e19dd09e8c0f6a88ac
ffffffff
01
80d6e34c00000000
19
76a9147971da00aa2aae27e2ff5d801a602014453c4c2c88ac
00000000

To this I append a four-byte hash code type 41000000.
01000000
01
a9c1fc526cd2dec545130868f7922d5c1f52bab84c70e97750c8365373b29870
00000000
19
76a914edc822bff914a255b819156c70e19dd09e8c0f6a88ac
ffffffff
01
80d6e34c00000000
19
76a9147971da00aa2aae27e2ff5d801a602014453c4c2c88ac
00000000
41000000

Now I compute the sha256 hash of this two times which yields:
f6b38f93c859db4920f22a1cd07d6c615a503ce89a7b2a3d90babad521b26062

Now I sign the result in 3. This could be where I am doing something wrong. The signature results in:
r = 767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa6131
s = 6dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136

and then I encode it into DER format as
30440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136

Does this look right?
To this signature I append the one-byte hash code type 41:
30440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e64613641

Then I prepend the length of the result of 5:
4730440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e64613641

Then I append 2103ce9f14cccee963def0f3a50978daa2dd91905eb11958da2c83e44c0ebb585c72 (the length of the public key + the actual public key) to the result of 6 yielding:
4730440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136412103ce9f14cccee963def0f3a50978daa2dd91905eb11958da2c83e44c0ebb585c72

The result of 7 is my signature, its length is 0x6a, so now I replace the scriptSig_length and scriptSig in 1 with this data yielding:
01000000
01
a9c1fc526cd2dec545130868f7922d5c1f52bab84c70e97750c8365373b29870
00000000
6a
4730440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136412103ce9f14cccee963def0f3a50978daa2dd91905eb11958da2c83e44c0ebb585c72
ffffffff
01
80d6e34c00000000
19
76a9147971da00aa2aae27e2ff5d801a602014453c4c2c88ac
00000000


This is my raw transaction, but when I try to send it I get the following error:
16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)

Can anyone tell me what I did wrong? Thank you very much!

user41755: Although you have followed the steps correctly, you are trying to "reinvent the wheel" by trying to sign it yourself via a python script. 
Bitcoin Cash software, just like bitcoin will provide you with the JSON RPC API's. These API's follow the reference implementation and already provide you with all the steps in built which you just performed. 
As an example/tutorial you can go through the tutorial available on bitcoin.org which is very concise and explanatory.
Do note that you need a running node for you to be able to access the API's

user208: Bitcoin Cash does not use the original Bitcoin sighash scheme (which looks like what you're trying to do here).
Instead, it uses a variant of the sighash scheme that was proposed in BIP143 (which is used for Segregated Witness transactions in Bitcoin).

82868: <p>I am trying to construct a raw transaction for bitcoin cash testnet. I have made a lot of use out of this <a href="https://bitcoin.stackexchange.com/a/5241/82868">very nice answer</a> to how to construct a raw transaction, but am still unable to construct a correct one myself. I would like to spend the the first output <a href="https://www.blocktrail.com/tBCC/tx/7098b2735336c85077e9704cb8ba521f5c2d92f768081345c5ded26c52fcc1a9" rel="nofollow noreferrer">7098b2735336c85077e9704cb8ba521f5c2d92f768081345c5ded26c52fcc1a9</a>.</p>

<p>Here is what I do:</p>

<ol>
<li><p>Create a transaction using the previous transaction hash and index with the scriptSig filled in with the scriptPubKey of the output I want to redeem. The raw transaction looks like this:</p>

<pre><code>01000000
01
a9c1fc526cd2dec545130868f7922d5c1f52bab84c70e97750c8365373b29870
00000000
19
76a914edc822bff914a255b819156c70e19dd09e8c0f6a88ac
ffffffff
01
80d6e34c00000000
19
76a9147971da00aa2aae27e2ff5d801a602014453c4c2c88ac
00000000
</code></pre></li>
<li><p>To this I append a four-byte hash code type 41000000.</p>

<pre><code>01000000
01
a9c1fc526cd2dec545130868f7922d5c1f52bab84c70e97750c8365373b29870
00000000
19
76a914edc822bff914a255b819156c70e19dd09e8c0f6a88ac
ffffffff
01
80d6e34c00000000
19
76a9147971da00aa2aae27e2ff5d801a602014453c4c2c88ac
00000000
41000000
</code></pre></li>
<li><p>Now I compute the sha256 hash of this two times which yields:</p>

<pre><code>f6b38f93c859db4920f22a1cd07d6c615a503ce89a7b2a3d90babad521b26062
</code></pre></li>
<li><p>Now I sign the result in 3. This could be where I am doing something wrong. The signature results in:</p>

<pre><code>r = 767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa6131
s = 6dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136
</code></pre>

<p>and then I encode it into DER format as</p>

<pre><code>30440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136
</code></pre>

<p>Does this look right?</p></li>
<li><p>To this signature I append the one-byte hash code type 41:</p>

<pre><code>30440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e64613641
</code></pre></li>
<li><p>Then I prepend the length of the result of 5:</p>

<pre><code>4730440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e64613641
</code></pre></li>
<li><p>Then I append <code>2103ce9f14cccee963def0f3a50978daa2dd91905eb11958da2c83e44c0ebb585c72</code> (the length of the public key + the actual public key) to the result of 6 yielding:</p>

<pre><code>4730440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136412103ce9f14cccee963def0f3a50978daa2dd91905eb11958da2c83e44c0ebb585c72
</code></pre></li>
<li><p>The result of 7 is my signature, its length is 0x6a, so now I replace the scriptSig_length and scriptSig in 1 with this data yielding:</p>

<pre><code>01000000
01
a9c1fc526cd2dec545130868f7922d5c1f52bab84c70e97750c8365373b29870
00000000
6a
4730440220767fb3ae5c9cab9a5afae16289e672a9723bcea919c429fc9cc6449d0baa613102206dcaab24e992565473c0e080d934df239c3bbb5f7869ac92d93f598a9e646136412103ce9f14cccee963def0f3a50978daa2dd91905eb11958da2c83e44c0ebb585c72
ffffffff
01
80d6e34c00000000
19
76a9147971da00aa2aae27e2ff5d801a602014453c4c2c88ac
00000000
</code></pre></li>
</ol>

<p>This is my raw transaction, but when I try to send it I get the following error:</p>

<pre><code>16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)
</code></pre>

<p>Can anyone tell me what I did wrong? Thank you very much!</p>
 41755: <p>Although you have followed the steps correctly, you are trying to "reinvent the wheel" by trying to sign it yourself via a python script. 
Bitcoin Cash software, just like bitcoin will provide you with the JSON RPC API's. These API's follow the reference implementation and already provide you with all the steps in built which you just performed. 
As an example/tutorial you can go through the <a href="https://bitcoin.org/en/developer-examples#transaction-tutorial" rel="nofollow noreferrer">tutorial</a> available on bitcoin.org which is very concise and explanatory.</p>

<p>Do note that you need a running node for you to be able to access the API's</p>
 208: <p>Bitcoin Cash does not use the original Bitcoin sighash scheme (which looks like what you're trying to do here).</p>

<p>Instead, it uses a variant of the sighash scheme that was proposed in BIP143 (which is used for Segregated Witness transactions in Bitcoin).</p>
