<p>The wallet does not know how to sign for segwit stuff until you use <code>addwitnessaddress</code>. This is because it is only tracking the P2PKH outputs for that key. You have to explicitly tell it to track the witness outputs for the key by using <code>addwitnessaddress</code>.</p>

CC BY-SA 3.0
2017-09-12T11:52:53.663Z
Thank you. I was actually looking to run the node with the wallet disabled. Any quick ideas on how that could be done (in the future)? I'm still digging through code, this seems to be the key piece:             pwalletMain->AddCScript(witscript);
tbee
CC BY-SA 3.0
2017-09-12T16:13:11.947Z
There is a plan to implement segwit support in the wallet for Bitcoin Core 0.15.1. The current plan is to just have it essentially do `addwitnessaddress` for all new addresses and give out those segwit addresses.
Ava Chow
CC BY-SA 3.0
2017-12-11T01:11:46.477Z
Updated note: segwit wallet support is aimed for 0.16.0 because the schedule was pushed back slightly by the S2X drama
meshcollider
CC BY-SA 3.0
2017-12-27T18:07:45.570Z
Does the 'addwitnessaddress' need to be specified and if so how?
Peter
CC BY-SA 3.0
2017-12-27T20:14:58.130Z
@Peter `addwitnessaddress` is a command, not something that is specified.
Ava Chow
CC BY-SA 3.0
2017-09-11T23:08:53.023Z
2017-09-11T23:08:53.023Z
Ava Chow
<p>Issue was missing the <code>amount</code> in the utxo given to signrawtransaction.
I attached the field at the end:</p>

<pre><code>signrawtransaction  
020000000117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa4030000000000ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac00000000  
'[{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0,"scriptPubKey":"a91421ce1507d06ed2742be0bf18a018bbcdd812a26487","redeemScript":"00149835f2e0dff9d7f6a4060140696bc7e00b12edd5","amount":0.85}]' 
'["cMahea7zqjxryy6NWaKxmhDyb1JzuNKCZAg8sxaJoXSBkRXjnib9"]'
</code></pre>

<p>Spend at <code>59fdf1c39236498debdab39302e57b370e0e4d94d856d52d923868cfe5ef4f1b</code></p>

CC BY-SA 3.0
2018-01-26T13:13:10.387Z
2018-01-26T13:13:10.387Z
arubi
<p>I'm trying to spend a SegWit output on testnet using the Bitcoin core's RPC commands.
Without importing the private key into my wallet (i.e. w/o addwitnessaddress).
I wonder if anyone had luck spending SegWit outputs this way? Perhaps the <strong>signrawtransaction</strong> is broken in this case?
Here are the commands and my results.
What's weird is that even though the <strong>signrawtransaction</strong> itself is successful, the transaction is not valid (rejected by <strong>sendrawtransaction</strong> and rejected by block explorers as I'm trying to push it, as well).</p>

<p>(Please note: every time I import the key into the wallet and do an "addwitnessaddress" everything works just fine).</p>

<p><code>./bitcoin-cli -testnet createrawtransaction '[{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0}]' '{"mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf":0.8}'</code> </p>

<p><code>020000000117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa4030000000000ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac00000000</code></p>

<p>./bitcoin-cli -testnet <em>signrawtransaction</em> 020000000117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa4030000000000ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac00000000 '[{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0,"scriptPubKey":"a91421ce1507d06ed2742be0bf18a018bbcdd812a26487","redeemScript":"00149835f2e0dff9d7f6a4060140696bc7e00b12edd5"}]' '["cMahea7zqjxryy6NWaKxmhDyb1JzuNKCZAg8sxaJoXSBkRXjnib9"]' </p>

<p><strong>{
  "hex": "0200000000010117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa40300000000171600149835f2e0dff9d7f6a4060140696bc7e00b12edd5ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac024730440220452a58cf56c45edaffb952acccd2f6f2cea523cf82e73b82f8eb5e3b3b1b17c4022011de26884cf693b12f16fdd8fa6c1d96dacb97050907353852895d9b80b3fae101210206f4bad90006f70112129815b25ba585484f1bb4f8b88f8ebaec2c76f543794300000000",
  "complete": true
}</strong></p>

<p>./bitcoin-cli -testnet <em>sendrawtransaction</em> 0200000000010117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa40300000000171600149835f2e0dff9d7f6a4060140696bc7e00b12edd5ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac024730440220452a58cf56c45edaffb952acccd2f6f2cea523cf82e73b82f8eb5e3b3b1b17c4022011de26884cf693b12f16fdd8fa6c1d96dacb97050907353852895d9b80b3fae101210206f4bad90006f70112129815b25ba585484f1bb4f8b88f8ebaec2c76f543794300000000</p>

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

<bitcoin-core><raw-transaction><segregated-witness><p2sh><signrawtransaction>
signrawtransaction of a P2SH-P2WPKH spend seems to be broken?
tbee
# signrawtransaction of a P2SH-P2WPKH spend seems to be broken?

(Asked by: username_0 on 2017-09-11)

I'm trying to spend a SegWit output on testnet using the Bitcoin core's RPC commands.
Without importing the private key into my wallet (i.e. w/o addwitnessaddress).
I wonder if anyone had luck spending SegWit outputs this way? Perhaps the **signrawtransaction** is broken in this case?
Here are the commands and my results.
What's weird is that even though the **signrawtransaction** itself is successful, the transaction is not valid (rejected by **sendrawtransaction** and rejected by block explorers as I'm trying to push it, as well).

(Please note: every time I import the key into the wallet and do an "addwitnessaddress" everything works just fine).

`./bitcoin-cli -testnet createrawtransaction '[{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0}]' '{"mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf":0.8}'`

`020000000117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa4030000000000ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac00000000`

./bitcoin-cli -testnet *signrawtransaction* 020000000117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa4030000000000ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac00000000 '[{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0,"scriptPubKey":"a91421ce1507d06ed2742be0bf18a018bbcdd812a26487","redeemScript":"00149835f2e0dff9d7f6a4060140696bc7e00b12edd5"}]' '["cMahea7zqjxryy6NWaKxmhDyb1JzuNKCZAg8sxaJoXSBkRXjnib9"]'

**{
"hex": "0200000000010117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa40300000000171600149835f2e0dff9d7f6a4060140696bc7e00b12edd5ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac024730440220452a58cf56c45edaffb952acccd2f6f2cea523cf82e73b82f8eb5e3b3b1b17c4022011de26884cf693b12f16fdd8fa6c1d96dacb97050907353852895d9b80b3fae101210206f4bad90006f70112129815b25ba585484f1bb4f8b88f8ebaec2c76f543794300000000",
"complete": true
}**

./bitcoin-cli -testnet *sendrawtransaction* 0200000000010117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa40300000000171600149835f2e0dff9d7f6a4060140696bc7e00b12edd5ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac024730440220452a58cf56c45edaffb952acccd2f6f2cea523cf82e73b82f8eb5e3b3b1b17c4022011de26884cf693b12f16fdd8fa6c1d96dacb97050907353852895d9b80b3fae101210206f4bad90006f70112129815b25ba585484f1bb4f8b88f8ebaec2c76f543794300000000

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

**Tags:** bitcoin-core, raw-transaction, segregated-witness, p2sh, signrawtransaction


---

## 2 answers

### Answer by username_1 on 2017-09-11. Score: 1

The wallet does not know how to sign for segwit stuff until you use `addwitnessaddress`. This is because it is only tracking the P2PKH outputs for that key. You have to explicitly tell it to track the witness outputs for the key by using `addwitnessaddress`.

> **Comments:**
> **username_0**: Thank you. I was actually looking to run the node with the wallet disabled. Any quick ideas on how that could be done (in the future)? I'm still digging through code, this seems to be the key piece:             pwalletMain->AddCScript(witscript);  
> **username_1**: There is a plan to implement segwit support in the wallet for Bitcoin Core 0.15.1. The current plan is to just have it essentially do `addwitnessaddress` for all new addresses and give out those segwit addresses.  
> **username_2**: Updated note: segwit wallet support is aimed for 0.16.0 because the schedule was pushed back slightly by the S2X drama  
> **username_3**: Does the 'addwitnessaddress' need to be specified and if so how?  
> **username_1**: @username_3 `addwitnessaddress` is a command, not something that is specified.  

---

### Answer by username_4 on 2018-01-26. Score: 0

Issue was missing the `amount` in the utxo given to signrawtransaction.
I attached the field at the end:

```
signrawtransaction  
020000000117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa4030000000000ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac00000000  
'[{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0,"scriptPubKey":"a91421ce1507d06ed2742be0bf18a018bbcdd812a26487","redeemScript":"00149835f2e0dff9d7f6a4060140696bc7e00b12edd5","amount":0.85}]' 
'["cMahea7zqjxryy6NWaKxmhDyb1JzuNKCZAg8sxaJoXSBkRXjnib9"]'

```

Spend at `59fdf1c39236498debdab39302e57b370e0e4d94d856d52d923868cfe5ef4f1b`


---

