<p>An error -26 almost always means your sighash is not constructed properly or that you did not hash it correctly. Unlike most other things in Bitcoin, sighashes are only hashed <strong>once</strong>.</p>
<p>In these cases, I recommend you cross-reference your sighashes and raw transactions by those generated by other programs. If you know Python then <a href="https://github.com/ofek/bit/" rel="nofollow noreferrer">bit</a> is a good library to start with as you can clone the repository and add some PDB breakpoints on the lines where the sighashes are made so that you can look at them for yourself.</p>

CC BY-SA 4.0
2024-01-20T11:34:23.220Z
2024-01-20T11:34:23.220Z
Zenul_Abidin
<p>Finally I was able to create a raw transaction, sign it on the HSM and broadcast it. Here is my working example:</p>

<p>The transaction from which I want to spend:</p>

<pre><code>{
    "error": null,
    "id": "1",
    "result": {
        "hash": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
        "hex": "0100000001661b9987b96a6ff5731b045cd4c6bbaccbd4947996b789fcfc48d93e958b006a010000008b483045022100dc4da7f2b24090c9df8af280b3809bbfc7f8bc869bfaa16d7feb4f986562071602200ea902b3602435128663eaf6ae3d9652f4b8c9038225a7a2f4b820f741fa81190141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff0200e1f505000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388aca0f7a6ca000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000",
        "locktime": 0,
        "size": 258,
        "txid": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3045022100dc4da7f2b24090c9df8af280b3809bbfc7f8bc869bfaa16d7feb4f986562071602200ea902b3602435128663eaf6ae3d9652f4b8c9038225a7a2f4b820f741fa8119[ALL] 049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b",
                    "hex": "483045022100dc4da7f2b24090c9df8af280b3809bbfc7f8bc869bfaa16d7feb4f986562071602200ea902b3602435128663eaf6ae3d9652f4b8c9038225a7a2f4b820f741fa81190141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b"
                },
                "sequence": 4294967295,
                "txid": "6a008b953ed948fcfc89b7967994d4cbacbbc6d45c041b73f56f6ab987991b66",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 1
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 33.9994
            }
        ],
        "vsize": 258,
        "weight": 1032
    }
}
</code></pre>

<p>The serialized unsigned raw transaction hash:</p>

<pre><code>01000000018d4912584ccd0d517f3c698a647399260e6762e0f9d787c17e7a35199b4c8e1a010000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff0200e1f505000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ac80c8b0c4000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000
</code></pre>

<p>The decoded unsigned raw transaction:</p>

<pre><code>{
    "error": null,
    "id": "1",
    "result": {
        "hash": "338615b2f4ece5132c3a275b8559863061e6eb1acdcf237a63c4d11980fb8aba",
        "locktime": 0,
        "size": 144,
        "txid": "338615b2f4ece5132c3a275b8559863061e6eb1acdcf237a63c4d11980fb8aba",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac"
                },
                "sequence": 4294967295,
                "txid": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 1
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 32.9992
            }
        ],
        "vsize": 144,
        "weight": 576
    }
}
</code></pre>

<p>The signature of the signed raw transaction:</p>

<pre><code>3045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e122
</code></pre>

<p>The public key:</p>

<pre><code>3056301006072a8648ce3d020106052b8104000a034200049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b
</code></pre>

<p>The serialized signed transaction:</p>

<pre><code>01000000018d4912584ccd0d517f3c698a647399260e6762e0f9d787c17e7a35199b4c8e1a010000008b483045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e1220141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff0280285b01000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ac00000000000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000
</code></pre>

<p>The decoded signed transaction:</p>

<pre><code>{
    "error": null,
    "id": "1",
    "result": {
        "hash": "8855a7927cffd939fc9f42933c84cc6a584a1cf76225c2b30963e2103041c1ae",
        "locktime": 0,
        "size": 258,
        "txid": "8855a7927cffd939fc9f42933c84cc6a584a1cf76225c2b30963e2103041c1ae",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e122[ALL] 049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b",
                    "hex": "483045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e1220141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b"
                },
                "sequence": 4294967295,
                "txid": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 0.2275136
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 0
            }
        ],
        "vsize": 258,
        "weight": 1032
    }
}
</code></pre>

CC BY-SA 4.0
2020-04-27T12:06:12.700Z
2020-04-27T12:06:12.700Z
Bumblebee
<p>The problem is that you are serializing the transaction for signing incorrectly. The data that is signed is not just the raw transaction with the sighash appended to it. You need to slightly modify it too. Specifically, for the input currently being signed, you need to put the <code>scriptCode</code> into that input's <code>scriptSig</code>. The <code>scriptSig</code>s of all other inputs must be empty.</p>

<p>The <code>scriptCode</code> is the <code>scriptPubKey</code> of the output being spent by that input except for P2SH. If the output is a P2SH output, then you need to use the <code>redeemScript</code>.</p>

<p>So you should be signing:</p>

<pre><code>0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ace0749dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000
</code></pre>

<p>Furthermore, Bitcoin uses double sha256. If your HSM hashes the message with SHA256, then you need to give it the first hash. So you have to hash the above once with SHA256 then give that hash to the HSM. If it just takes the hash, then you need to hash it with SHA256 twice.</p>

CC BY-SA 4.0
2020-04-26T18:15:02.850Z
Thank you very much. I changed it in the application and updated my original question accordingly. No I get the same output as yours. The HSM doesn't do any hashing. I double sha256 the serialized transaction which results in the following hash: ```bf2fa5a5f3fbc93f4b4db2f7a43f8b45ecfb2bdccfb80d55843cd9a0841c94fc``` Then I send this hash with the public key to the HSM and it returns the signature. But I still get the same error.
Bumblebee
CC BY-SA 4.0
2020-04-26T19:07:24.453Z
Just to make sure: I have to sign the transaction with the private key of the address, which is in vout of the transaction from which I want to spend. in my case: ```moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6``` Correct?
Bumblebee
CC BY-SA 4.0
2020-04-26T19:54:27.427Z
There's a discrepancy between raw original raw transaction and the signed one. The signed one has an output with a value of 34.9996 but the non-signed one is 34.9998.
Ava Chow
CC BY-SA 4.0
2020-04-27T05:36:33.243Z
I read somewhere, that in the raw original transaction the sum of the values in vout, has to match the the value of the vout of the unspent transaction output. Is that wrong? 
Now I calculate the values in the raw original transaction and the signed transaction like this: totalUspent - transactionValue - transactionFee (0.0002). Is that correct? I updated it again in my original question, but I still get the same error.
Bumblebee
CC BY-SA 4.0
2020-04-27T05:56:11.807Z
The unsigned transaction is exactly the same as the signed one except the scriptSigs are empty. The values are the same as in the final transaction. It is highly likely that you are misunderstanding whatever it is that you read. Your hash is now just completely wrong. I don't know how you calculated that hash as the data you are supposed to be hashing is correct.
Ava Chow
CC BY-SA 4.0
2020-04-27T07:18:15.673Z
Now I got it. I was able to broadcast the transaction without any errors. Thank you very much for your help. I will post the working example below.
Bumblebee
CC BY-SA 4.0
2020-04-27T16:32:35.057Z
Now I would like to create a raw transactions out of multiple UTXOs. I didn't fully understand your answer above. I've posted a new question for this: https://bitcoin.stackexchange.com/questions/95546/how-does-vin-have-to-look-like-with-multiple-inputs-in-a-raw-transaction
Bumblebee
CC BY-SA 4.0
2022-06-11T17:48:58.280Z
@AndrewChow thanks, so if I'm about to spend a custom script P2SH output, the redeemscript is also used as placeholder for scriptSig in the dummy tx to create the message to sign. Well, I must have some other error around, thanks anyway for confirming that!
T. Rossi
CC BY-SA 4.0
2022-06-09T16:43:20.130Z
I'm sorry for the delving but it's not very widespread information: w.r.t. P2SH scriptCode what do you mean "then you need to use the redeemScript.", is it the default "OPHASH160 OP_PUSHBYTES_20 scriptHash OP_EQUAL" used by the output to be spent, or the custom script that will be used in the redeemScript?
T. Rossi
CC BY-SA 4.0
2022-06-10T14:39:10.913Z
@T.Rossi The redeemScript is the custom script.
Ava Chow
CC BY-SA 4.0
2020-04-26T17:58:21.860Z
2020-04-26T17:58:21.860Z
Ava Chow
<p>I've created a raw transaction, and I get this error when I try to send it with sendrawtransaction to my local bitcoin regtest:</p>

<pre><code>{
    "error": {
        "code": -26,
        "message": "mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)"
    },
    "id": "1",
    "result": null
}
</code></pre>

<p>This is the transaction from which I want to spend:</p>

<pre><code>{
    "error": null,
    "id": "1",
    "result": {
        "hash": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
        "hex": "0200000001c1c8886fe4e25ee471423e000532412b387fb0fea11a17a68cea09c122229e2c010000006a473044022029296a6ac3fdaf0a0c4616c783bee1b3b5f7ea24a63f3df3544e74aa4c1a65b102207baa71419ef0ceff6218e78b6fb93bfe6ac7445584e23d20be1fbf6454bab50f012102a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2effffffff01e0d96aee000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000",
        "locktime": 0,
        "size": 191,
        "txid": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
        "version": 2,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3044022029296a6ac3fdaf0a0c4616c783bee1b3b5f7ea24a63f3df3544e74aa4c1a65b102207baa71419ef0ceff6218e78b6fb93bfe6ac7445584e23d20be1fbf6454bab50f[ALL] 02a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2e",
                    "hex": "473044022029296a6ac3fdaf0a0c4616c783bee1b3b5f7ea24a63f3df3544e74aa4c1a65b102207baa71419ef0ceff6218e78b6fb93bfe6ac7445584e23d20be1fbf6454bab50f012102a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2e"
                },
                "sequence": 4294967295,
                "txid": "2c9e2222c109ea8ca6171aa1feb07f382b413205003e4271e45ee2e46f88c8c1",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 39.9998
            }
        ],
        "vsize": 191,
        "weight": 764
    }
}
</code></pre>

<p>I performed the following steps:</p>

<ol>
<li>Create the raw transaction. This is the raw transaction:</li>
</ol>

<pre><code>0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000
</code></pre>

<pre><code>{
    "error": null,
    "id": "1",
    "result": {
        "hash": "16fa981ab0af1b0516467f80c71ced3e6b0d58e3fdd80137320029633dce1881",
        "locktime": 0,
        "size": 144,
        "txid": "16fa981ab0af1b0516467f80c71ced3e6b0d58e3fdd80137320029633dce1881",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac"
                },
                "sequence": 4294967295,
                "txid": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
                "vout": 0
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 5
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 34.9996
            }
        ],
        "vsize": 144,
        "weight": 576
    }
}
</code></pre>

<ol start="2">
<li>Add 01000000 at the of the transaction. This is the hex of the transaction before signing:</li>
</ol>

<pre><code>0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac0000000001000000
</code></pre>

<ol start="3">
<li>Double SHA256 the raw transaction from step 2. This is the hash:</li>
</ol>

<pre><code>0b5a635ff615175cb114f051ea89e3f90e373dc059fc5ec8059ceeea4b42099f
</code></pre>

<ol start="4">
<li>Sign the transaction. To sign the transaction I have to use an endpoint of an HSM. I have to send the public key and the hex of the transaction and it returns the signature. The returned signature looks like this:</li>
</ol>

<pre><code>3044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d289451
</code></pre>

<p>This is the public key:</p>

<pre><code>3056301006072a8648ce3d020106052b8104000a034200049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b
</code></pre>

<p>This is the signed transaction:</p>

<pre><code>0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000008a473044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d2894510141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000
</code></pre>

<pre><code>{
    "error": null,
    "id": "1",
    "result": {
        "hash": "5fcf741fba06e52692d731e69bf937e1e92d0439b3976f54dc733a90dd93a288",
        "locktime": 0,
        "size": 257,
        "txid": "5fcf741fba06e52692d731e69bf937e1e92d0439b3976f54dc733a90dd93a288",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d289451[ALL] 049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b",
                    "hex": "473044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d2894510141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b"
                },
                "sequence": 4294967295,
                "txid": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
                "vout": 0
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 5
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 34.9996
            }
        ],
        "vsize": 257,
        "weight": 1028
    }
}
</code></pre>

<ol start="5">
<li>Send the signed transaction with rpc <code>sendrawtransaction</code>:</li>
</ol>

<pre><code>{"id":"1","jsonrpc":"1.0","method":"sendrawtransaction","params":["0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000008a473044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d2894510141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000"]}
</code></pre>

<p><code>sendrawtransaction</code> returns the following error:</p>

<pre><code>{
    "error": {
        "code": -26,
        "message": "mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)"
    },
    "id": "1",
    "result": null
}
</code></pre>

<p>What does this error mean? What am I doing wrong?</p>

CC BY-SA 4.0
2020-04-25T21:46:00.783Z
How does the HSM sign the transaction? Does it understand that it is a Bitcoin transaction and needs to be serialized in a certain way before signing? Does it know that it needs to be hashed twice with SHA256? Or is it just a generic HSM that hashes things once and makes the signature?
Ava Chow
CC BY-SA 4.0
2020-04-26T06:34:21.110Z
I serialize and hash the transaction (see step 2 above) before sending it to the HSM. It just signs the byte array with the private key, which belongs to the public key, and returns the signature.
Bumblebee
CC BY-SA 4.0
2020-04-26T07:18:41.953Z
... and the signature seems to be valid. The HSM also has an endpoint to verify the signature. It returns true if I verify it.
Bumblebee
CC BY-SA 4.0
2020-04-26T15:18:39.987Z
After some source code reading, I found out that my transactions most probably fails here: https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L368 Now the question is, which conditions triggers the failure.
Bumblebee
CC BY-SA 4.0
2020-04-26T15:43:11.867Z
This error message just means your signature is wrong (most likely because you're signing the wrong thing).
Pieter Wuille
CC BY-SA 4.0
2020-04-26T16:01:30.507Z
Does that mean that there is something wrong with the unsigned raw transaction? Can somebody have a look at it and maybe point out what is wrong with it?
Bumblebee
<bitcoin-core>
Error -26: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)
Bumblebee
# Error -26: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)

(Asked by: username_0 on 2020-04-25)

I've created a raw transaction, and I get this error when I try to send it with sendrawtransaction to my local bitcoin regtest:

```
{
    "error": {
        "code": -26,
        "message": "mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)"
    },
    "id": "1",
    "result": null
}

```

This is the transaction from which I want to spend:

```
{
    "error": null,
    "id": "1",
    "result": {
        "hash": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
        "hex": "0200000001c1c8886fe4e25ee471423e000532412b387fb0fea11a17a68cea09c122229e2c010000006a473044022029296a6ac3fdaf0a0c4616c783bee1b3b5f7ea24a63f3df3544e74aa4c1a65b102207baa71419ef0ceff6218e78b6fb93bfe6ac7445584e23d20be1fbf6454bab50f012102a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2effffffff01e0d96aee000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000",
        "locktime": 0,
        "size": 191,
        "txid": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
        "version": 2,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3044022029296a6ac3fdaf0a0c4616c783bee1b3b5f7ea24a63f3df3544e74aa4c1a65b102207baa71419ef0ceff6218e78b6fb93bfe6ac7445584e23d20be1fbf6454bab50f[ALL] 02a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2e",
                    "hex": "473044022029296a6ac3fdaf0a0c4616c783bee1b3b5f7ea24a63f3df3544e74aa4c1a65b102207baa71419ef0ceff6218e78b6fb93bfe6ac7445584e23d20be1fbf6454bab50f012102a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2e"
                },
                "sequence": 4294967295,
                "txid": "2c9e2222c109ea8ca6171aa1feb07f382b413205003e4271e45ee2e46f88c8c1",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 39.9998
            }
        ],
        "vsize": 191,
        "weight": 764
    }
}

```

I performed the following steps:

1. Create the raw transaction. This is the raw transaction:

```
0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000

```

```
{
    "error": null,
    "id": "1",
    "result": {
        "hash": "16fa981ab0af1b0516467f80c71ced3e6b0d58e3fdd80137320029633dce1881",
        "locktime": 0,
        "size": 144,
        "txid": "16fa981ab0af1b0516467f80c71ced3e6b0d58e3fdd80137320029633dce1881",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac"
                },
                "sequence": 4294967295,
                "txid": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
                "vout": 0
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 5
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 34.9996
            }
        ],
        "vsize": 144,
        "weight": 576
    }
}

```

2. Add 01000000 at the of the transaction. This is the hex of the transaction before signing:

```
0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac0000000001000000

```

3. Double SHA256 the raw transaction from step 2. This is the hash:

```
0b5a635ff615175cb114f051ea89e3f90e373dc059fc5ec8059ceeea4b42099f

```

4. Sign the transaction. To sign the transaction I have to use an endpoint of an HSM. I have to send the public key and the hex of the transaction and it returns the signature. The returned signature looks like this:

```
3044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d289451

```

This is the public key:

```
3056301006072a8648ce3d020106052b8104000a034200049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b

```

This is the signed transaction:

```
0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000008a473044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d2894510141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000

```

```
{
    "error": null,
    "id": "1",
    "result": {
        "hash": "5fcf741fba06e52692d731e69bf937e1e92d0439b3976f54dc733a90dd93a288",
        "locktime": 0,
        "size": 257,
        "txid": "5fcf741fba06e52692d731e69bf937e1e92d0439b3976f54dc733a90dd93a288",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d289451[ALL] 049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b",
                    "hex": "473044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d2894510141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b"
                },
                "sequence": 4294967295,
                "txid": "95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2",
                "vout": 0
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 5
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 34.9996
            }
        ],
        "vsize": 257,
        "weight": 1028
    }
}

```

5. Send the signed transaction with rpc `sendrawtransaction`:

```
{"id":"1","jsonrpc":"1.0","method":"sendrawtransaction","params":["0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000008a473044022052fe83beb097408e84d138bc4f723507f626b0f07019385df2103ebfc559a67a02206b5281554dfd80f1a29a0257d9cdfe07a7f7684d52c6ef875678ea3e3d2894510141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388acc0269dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000"]}

```

`sendrawtransaction` returns the following error:

```
{
    "error": {
        "code": -26,
        "message": "mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)"
    },
    "id": "1",
    "result": null
}

```

What does this error mean? What am I doing wrong?

**Tags:** bitcoin-core

> **Comments:**
> **username_1**: How does the HSM sign the transaction? Does it understand that it is a Bitcoin transaction and needs to be serialized in a certain way before signing? Does it know that it needs to be hashed twice with SHA256? Or is it just a generic HSM that hashes things once and makes the signature?  
> **username_0**: I serialize and hash the transaction (see step 2 above) before sending it to the HSM. It just signs the byte array with the private key, which belongs to the public key, and returns the signature.  
> **username_0**: ... and the signature seems to be valid. The HSM also has an endpoint to verify the signature. It returns true if I verify it.  
> **username_0**: After some source code reading, I found out that my transactions most probably fails here: https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L368 Now the question is, which conditions triggers the failure.  
> **username_2**: This error message just means your signature is wrong (most likely because you're signing the wrong thing).  
> **username_0**: Does that mean that there is something wrong with the unsigned raw transaction? Can somebody have a look at it and maybe point out what is wrong with it?  

---

## 3 answers

### Answer by username_1 on 2020-04-26. Score: 4 | Accepted answer

The problem is that you are serializing the transaction for signing incorrectly. The data that is signed is not just the raw transaction with the sighash appended to it. You need to slightly modify it too. Specifically, for the input currently being signed, you need to put the `scriptCode` into that input's `scriptSig`. The `scriptSig`s of all other inputs must be empty.

The `scriptCode` is the `scriptPubKey` of the output being spent by that input except for P2SH. If the output is a P2SH output, then you need to use the `redeemScript`.

So you should be signing:

```
0100000001c220d5c6404a03347826f8375d3ef779c2e9d9d559050c3579eca2ddbbf6d495000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff020065cd1d000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ace0749dd0000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000

```

Furthermore, Bitcoin uses double sha256. If your HSM hashes the message with SHA256, then you need to give it the first hash. So you have to hash the above once with SHA256 then give that hash to the HSM. If it just takes the hash, then you need to hash it with SHA256 twice.

> **Comments:**
> **username_0**: Thank you very much. I changed it in the application and updated my original question accordingly. No I get the same output as yours. The HSM doesn't do any hashing. I double sha256 the serialized transaction which results in the following hash: ```bf2fa5a5f3fbc93f4b4db2f7a43f8b45ecfb2bdccfb80d55843cd9a0841c94fc``` Then I send this hash with the public key to the HSM and it returns the signature. But I still get the same error.  
> **username_0**: Just to make sure: I have to sign the transaction with the private key of the address, which is in vout of the transaction from which I want to spend. in my case: ```moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6``` Correct?  
> **username_1**: There's a discrepancy between raw original raw transaction and the signed one. The signed one has an output with a value of 34.9996 but the non-signed one is 34.9998.  
> **username_0**: I read somewhere, that in the raw original transaction the sum of the values in vout, has to match the the value of the vout of the unspent transaction output. Is that wrong?  Now I calculate the values in the raw original transaction and the signed transaction like this: totalUspent - transactionValue - transactionFee (0.0002). Is that correct? I updated it again in my original question, but I still get the same error.  
> **username_1**: The unsigned transaction is exactly the same as the signed one except the scriptSigs are empty. The values are the same as in the final transaction. It is highly likely that you are misunderstanding whatever it is that you read. Your hash is now just completely wrong. I don't know how you calculated that hash as the data you are supposed to be hashing is correct.  
> **username_0**: Now I got it. I was able to broadcast the transaction without any errors. Thank you very much for your help. I will post the working example below.  
> **username_0**: Now I would like to create a raw transactions out of multiple UTXOs. I didn't fully understand your answer above. I've posted a new question for this: https://bitcoin.stackexchange.com/questions/95546/how-does-vin-have-to-look-like-with-multiple-inputs-in-a-raw-transaction  
> **username_4**: I'm sorry for the delving but it's not very widespread information: w.r.t. P2SH scriptCode what do you mean "then you need to use the redeemScript.", is it the default "OPHASH160 OP_PUSHBYTES_20 scriptHash OP_EQUAL" used by the output to be spent, or the custom script that will be used in the redeemScript?  
> **username_1**: @T.username_4 The redeemScript is the custom script.  
> **username_4**: @AndrewChow thanks, so if I'm about to spend a custom script P2SH output, the redeemscript is also used as placeholder for scriptSig in the dummy tx to create the message to sign. Well, I must have some other error around, thanks anyway for confirming that!  

---

### Answer by username_3 on 2024-01-20. Score: 1

An error -26 almost always means your sighash is not constructed properly or that you did not hash it correctly. Unlike most other things in Bitcoin, sighashes are only hashed **once**.

In these cases, I recommend you cross-reference your sighashes and raw transactions by those generated by other programs. If you know Python then [bit](https://github.com/ofek/bit/) is a good library to start with as you can clone the repository and add some PDB breakpoints on the lines where the sighashes are made so that you can look at them for yourself.


---

### Answer by username_0 on 2020-04-27. Score: 0

Finally I was able to create a raw transaction, sign it on the HSM and broadcast it. Here is my working example:

The transaction from which I want to spend:

```
{
    "error": null,
    "id": "1",
    "result": {
        "hash": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
        "hex": "0100000001661b9987b96a6ff5731b045cd4c6bbaccbd4947996b789fcfc48d93e958b006a010000008b483045022100dc4da7f2b24090c9df8af280b3809bbfc7f8bc869bfaa16d7feb4f986562071602200ea902b3602435128663eaf6ae3d9652f4b8c9038225a7a2f4b820f741fa81190141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff0200e1f505000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388aca0f7a6ca000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000",
        "locktime": 0,
        "size": 258,
        "txid": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3045022100dc4da7f2b24090c9df8af280b3809bbfc7f8bc869bfaa16d7feb4f986562071602200ea902b3602435128663eaf6ae3d9652f4b8c9038225a7a2f4b820f741fa8119[ALL] 049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b",
                    "hex": "483045022100dc4da7f2b24090c9df8af280b3809bbfc7f8bc869bfaa16d7feb4f986562071602200ea902b3602435128663eaf6ae3d9652f4b8c9038225a7a2f4b820f741fa81190141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b"
                },
                "sequence": 4294967295,
                "txid": "6a008b953ed948fcfc89b7967994d4cbacbbc6d45c041b73f56f6ab987991b66",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 1
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 33.9994
            }
        ],
        "vsize": 258,
        "weight": 1032
    }
}

```

The serialized unsigned raw transaction hash:

```
01000000018d4912584ccd0d517f3c698a647399260e6762e0f9d787c17e7a35199b4c8e1a010000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488acffffffff0200e1f505000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ac80c8b0c4000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000

```

The decoded unsigned raw transaction:

```
{
    "error": null,
    "id": "1",
    "result": {
        "hash": "338615b2f4ece5132c3a275b8559863061e6eb1acdcf237a63c4d11980fb8aba",
        "locktime": 0,
        "size": 144,
        "txid": "338615b2f4ece5132c3a275b8559863061e6eb1acdcf237a63c4d11980fb8aba",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac"
                },
                "sequence": 4294967295,
                "txid": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 1
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 32.9992
            }
        ],
        "vsize": 144,
        "weight": 576
    }
}

```

The signature of the signed raw transaction:

```
3045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e122

```

The public key:

```
3056301006072a8648ce3d020106052b8104000a034200049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b

```

The serialized signed transaction:

```
01000000018d4912584ccd0d517f3c698a647399260e6762e0f9d787c17e7a35199b4c8e1a010000008b483045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e1220141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93bffffffff0280285b01000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ac00000000000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000

```

The decoded signed transaction:

```
{
    "error": null,
    "id": "1",
    "result": {
        "hash": "8855a7927cffd939fc9f42933c84cc6a584a1cf76225c2b30963e2103041c1ae",
        "locktime": 0,
        "size": 258,
        "txid": "8855a7927cffd939fc9f42933c84cc6a584a1cf76225c2b30963e2103041c1ae",
        "version": 1,
        "vin": [
            {
                "scriptSig": {
                    "asm": "3045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e122[ALL] 049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b",
                    "hex": "483045022100eac45a27b4acd459b386f18461b851e94a9f94bec8a2896af64bc57934926ca8022023cc300a10df5fdead368d6fbd4a109b06baadc920f5a893f3721faef669e1220141049665be7c887cc801b1f6c5bb189434aa0a0635cd23d3b62832ffe3be70e9a3af64b03bb1217ee29ff2a0d5a88ff433c531cef6ba29f080e047f24f7e612bd93b"
                },
                "sequence": 4294967295,
                "txid": "1a8e4c9b19357a7ec187d7f9e062670e269973648a693c7f510dcd4c5812498d",
                "vout": 1
            }
        ],
        "vout": [
            {
                "n": 0,
                "scriptPubKey": {
                    "addresses": [
                        "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
                    ],
                    "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 0.2275136
            },
            {
                "n": 1,
                "scriptPubKey": {
                    "addresses": [
                        "moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6"
                    ],
                    "asm": "OP_DUP OP_HASH160 59fe1a9f9f0a5af33396c59990f064be1ca51274 OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash"
                },
                "value": 0
            }
        ],
        "vsize": 258,
        "weight": 1032
    }
}

```


---

