<p>After writing up this question I finally figured out the answer from here: <a href="https://bitcointalk.org/index.php?topic=1680640.0" rel="nofollow noreferrer">https://bitcointalk.org/index.php?topic=1680640.0</a>.  I will answer my own question for anyone who might be having the same problem.  It turns out I needed to specify the amount of each input in <code>signrawtransaction</code>.</p>

<pre><code>bitcoin-cli signrawtransaction 0200000001cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000000ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8700000000 '[{"txid":"e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb","vout":0,"amount":0.00541855,"scriptPubKey":"a914184b69873b307dc7081f2541098aaf4881bac20187","redeemScript":"0014568db227e811df5f502df149c8c9d899492140c9"}]'
&gt;&gt; {"hex":"02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8702473044022006f8822e2a56fb4c9defaca393a0c4ee29a32b4caecc15e457dff1b5993e88290220096b1bae9819d64f2b69a44881c033fb7c9fbde77c9d16347ef2439e831c192d012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000","complete": true}
</code></pre>

<p>This time sending it works:</p>

<pre><code>bitcoin-cli sendrawtransaction 02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8702473044022006f8822e2a56fb4c9defaca393a0c4ee29a32b4caecc15e457dff1b5993e88290220096b1bae9819d64f2b69a44881c033fb7c9fbde77c9d16347ef2439e831c192d012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000
f375de743834e041f42a19eceb39fb25b4e6ea5159b5450ea3fdac95d67062dc
</code></pre>

<p>For some reason this wasn't necessary for spending regular P2PKH outputs but it seems that for P2SH outputs it is.  I am curious as to why this might be the case and why <code>signrawtransaction</code> didn't throw any errors.  I have to say that the documentation is very poor as <a href="https://bitcoin.org/en/developer-reference#signrawtransaction" rel="nofollow noreferrer">https://bitcoin.org/en/developer-reference#signrawtransaction</a> says nothing about including an amount in the parameter #2.</p>

CC BY-SA 3.0
2018-01-18T17:24:14.250Z
It's not P2SH that makes including the amount in sighash necessary, rather it's checksigs in segwit scripts.
You're spending a p2sh-p2wpkh, so you need to include the amount.
arubi
CC BY-SA 3.0
2018-01-18T17:22:06.360Z
2018-01-18T17:22:06.360Z
MrO
<p>I'm trying spend funds that were sent to an SegWit address I created with the <code>bitcoin-cli addwitnessaddress &lt;P2PKH address&gt;</code> command.  The segwit address created was
<code>33uUUt2V76HLcLqbs1Hou2ioofQo3d5kZ2</code>.  I sent a small amount to this address as a test.</p>

<pre><code>{txid: e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb, vout: 0}
</code></pre>

<p>I'm now trying to spend those funds to <code>3FNYRnLCgbGAaYmhkX1QHaXD5VYyXndpDa</code>.  I created a raw transaction the normal way by specifying inputs and outputs:</p>

<pre><code>bitcoin-cli createrawtransaction '[{"txid":"e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb","vout":0}]' '{"3FNYRnLCgbGAaYmhkX1QHaXD5VYyXndpDa":0.00451855}'
&gt;&gt; 0200000001cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000000ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8700000000

bitcoin-cli signrawtransaction 0200000001cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000000ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8700000000 '[{"txid":"e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb","vout":0,"scriptPubKey":"a914184b69873b307dc7081f2541098aaf4881bac20187","redeemScript":"0014568db227e811df5f502df149c8c9d899492140c9"}]'
&gt;&gt; {"hex": "02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d87024830450221009fe3df8448be56b052bcf81cb3e992ff606a10b1baf94eec49b1bad05914b97c0220752c6823152d0ef59945377a767edba6222a12b6e2b1baabafe498fa4801dea6012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000","complete": true}
</code></pre>

<p>Now I try to send the transaction:</p>

<pre><code>bitcoin-cli sendrawtransaction 02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d87024830450221009fe3df8448be56b052bcf81cb3e992ff606a10b1baf94eec49b1bad05914b97c0220752c6823152d0ef59945377a767edba6222a12b6e2b1baabafe498fa4801dea6012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000
</code></pre>

<p>And get the following error:</p>

<pre><code>error code: -26
error message:
64: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation)
</code></pre>

<p>I tried sending it through blockchain.info/pushtx in case it was a problem with my wallet but I got the same error.  I tried looking up what the error meant but couldn't find any explanation that would help me figure out what I did wrong.  </p>

<segregated-witness><bitcoin-cli><error><sendrawtransaction>
Error sending SegWit transaction: error code: -26 using bitcoin-cli
MrO
# Error sending SegWit transaction: error code: -26 using bitcoin-cli

(Asked by: username_0 on 2018-01-18)

I'm trying spend funds that were sent to an SegWit address I created with the `bitcoin-cli addwitnessaddress <P2PKH address>` command. The segwit address created was
`33uUUt2V76HLcLqbs1Hou2ioofQo3d5kZ2`. I sent a small amount to this address as a test.

```
{txid: e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb, vout: 0}

```

I'm now trying to spend those funds to `3FNYRnLCgbGAaYmhkX1QHaXD5VYyXndpDa`. I created a raw transaction the normal way by specifying inputs and outputs:

```
bitcoin-cli createrawtransaction '[{"txid":"e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb","vout":0}]' '{"3FNYRnLCgbGAaYmhkX1QHaXD5VYyXndpDa":0.00451855}'
>> 0200000001cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000000ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8700000000

bitcoin-cli signrawtransaction 0200000001cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000000ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8700000000 '[{"txid":"e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb","vout":0,"scriptPubKey":"a914184b69873b307dc7081f2541098aaf4881bac20187","redeemScript":"0014568db227e811df5f502df149c8c9d899492140c9"}]'
>> {"hex": "02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d87024830450221009fe3df8448be56b052bcf81cb3e992ff606a10b1baf94eec49b1bad05914b97c0220752c6823152d0ef59945377a767edba6222a12b6e2b1baabafe498fa4801dea6012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000","complete": true}

```

Now I try to send the transaction:

```
bitcoin-cli sendrawtransaction 02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d87024830450221009fe3df8448be56b052bcf81cb3e992ff606a10b1baf94eec49b1bad05914b97c0220752c6823152d0ef59945377a767edba6222a12b6e2b1baabafe498fa4801dea6012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000

```

And get the following error:

```
error code: -26
error message:
64: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation)

```

I tried sending it through blockchain.info/pushtx in case it was a problem with my wallet but I got the same error. I tried looking up what the error meant but couldn't find any explanation that would help me figure out what I did wrong.

**Tags:** segregated-witness, bitcoin-cli, error, sendrawtransaction


---

## 1 answers

### Answer by username_0 on 2018-01-18. Score: 2

After writing up this question I finally figured out the answer from here: <https://bitcointalk.org/index.php?topic=1680640.0>. I will answer my own question for anyone who might be having the same problem. It turns out I needed to specify the amount of each input in `signrawtransaction`.

```
bitcoin-cli signrawtransaction 0200000001cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000000ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8700000000 '[{"txid":"e360a6f86ebbdf0d2c3c86df60d1ad7e95af41248ff9305a48372db519028fcb","vout":0,"amount":0.00541855,"scriptPubKey":"a914184b69873b307dc7081f2541098aaf4881bac20187","redeemScript":"0014568db227e811df5f502df149c8c9d899492140c9"}]'
>> {"hex":"02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8702473044022006f8822e2a56fb4c9defaca393a0c4ee29a32b4caecc15e457dff1b5993e88290220096b1bae9819d64f2b69a44881c033fb7c9fbde77c9d16347ef2439e831c192d012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000","complete": true}

```

This time sending it works:

```
bitcoin-cli sendrawtransaction 02000000000101cb8f0219b52d37485a30f98f2441af957eadd160df863c2c0ddfbb6ef8a660e30000000017160014568db227e811df5f502df149c8c9d899492140c9ffffffff010fe506000000000017a9149613523d8525c0c444209b73eefda15101d1750d8702473044022006f8822e2a56fb4c9defaca393a0c4ee29a32b4caecc15e457dff1b5993e88290220096b1bae9819d64f2b69a44881c033fb7c9fbde77c9d16347ef2439e831c192d012103ba8ae62944f27ce7a661866d6837ab3d6dd3fcd62bc6a09be5405074ec2473db00000000
f375de743834e041f42a19eceb39fb25b4e6ea5159b5450ea3fdac95d67062dc

```

For some reason this wasn't necessary for spending regular P2PKH outputs but it seems that for P2SH outputs it is. I am curious as to why this might be the case and why `signrawtransaction` didn't throw any errors. I have to say that the documentation is very poor as <https://bitcoin.org/en/developer-reference#signrawtransaction> says nothing about including an amount in the parameter #2.

> **Comments:**
> **username_1**: It's not P2SH that makes including the amount in sighash necessary, rather it's checksigs in segwit scripts. You're spending a p2sh-p2wpkh, so you need to include the amount.  

---

