1

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)

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.

  • 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 Sep 12 '17 at 11:52
  • 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. – Andrew Chow Sep 12 '17 at 16:13
  • Updated note: segwit wallet support is aimed for 0.16.0 because the schedule was pushed back slightly by the S2X drama – MeshCollider Dec 11 '17 at 1:11
  • Does the 'addwitnessaddress' need to be specified and if so how? – Peter Dec 27 '17 at 18:07
  • @Peter addwitnessaddress is a command, not something that is specified. – Andrew Chow Dec 27 '17 at 20:14
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.