Error parsing JSON in bitcoin-cli signrawtransactionwithkey

2

I have issues trying to sign a 2/3 multisig tx with the first private key.

What am I doing something wrong or am I missing something for the arg?

Command format:

/usr/bin/bitcoin-cli -testnet signrawtransactionwithkey "multisig_tx_hexstring" \"privatekey1\"  {\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"}

Filled in:

/usr/bin/bitcoin-cli -testnet signrawtransactionwithkey "02000000017b0cd6ab6beebace32e00f27aea8092879e178a77d2d0e74d001e10b39f560d10100000000ffffffff0100093d000000000017a9145e235c002eb66a1c33abccfb805043a036baf7798700000000" \"cNoe7mVGEVFwUwQXuCJadosEVPYU5rcCVxzTr46gYWbWMD8gXR7b\"  {\"txid\":\"d160f5390be101d0740e2d7da778e1792809a8ae270fe032cebaee6babd60c7b\",\"vout\":1,\"scriptPubKey\":\"a9145c975f4c6d18fa1abd25018e1fa3c18e58c9e93b87\",\"redeemScript\":\"5221029558bd8bc6e0cac883cac93a420bf8e68e76e8e07944f6034e3c5eadd3f1a4db21038d217a8fa3960a3b3212bc545566c5c48add11003551cb23c0d744a13f9ab8272102fcd0e6ff324c7a3bc9a8e224d61cd9ccd244c54186848ca3035a54736a9780d653ae\"}

And the error:

error: Error parsing JSON:"txid":"d160f5390be101d0740e2d7da778e1792809a8ae270fe032cebaee6babd60c7b"

Tom

Posted 2018-12-06T01:56:23.057

Reputation: 21

you need to pack the JSON object in quotes `Jonas Schnelli 2018-12-06T02:07:18.953

Answers

2

Try this:

You need to provide the private keys and the utxo as arrays and make sure it is valid json and in quotes.

$ /usr/bin/bitcoin-cli -testnet signrawtransactionwithkey "02000000017b0cd6ab6beebace32e00f27aea8092879e178a77d2d0e74d001e10b39f560d10100000000ffffffff0100093d000000000017a9145e235c002eb66a1c33abccfb805043a036baf7798700000000" '["cNoe7mVGEVFwUwQXuCJadosEVPYU5rcCVxzTr46gYWbWMD8gXR7b"]' '[{"txid":"d160f5390be101d0740e2d7da778e1792809a8ae270fe032cebaee6babd60c7b","vout":1,"scriptPubKey":"a9145c975f4c6d18fa1abd25018e1fa3c18e58c9e93b87","redeemScript":"5221029558bd8bc6e0cac883cac93a420bf8e68e76e8e07944f6034e3c5eadd3f1a4db21038d217a8fa3960a3b3212bc545566c5c48add11003551cb23c0d744a13f9ab8272102fcd0e6ff324c7a3bc9a8e224d61cd9ccd244c54186848ca3035a54736a9780d653ae"}]'

JBaczuk

Posted 2018-12-06T01:56:23.057

Reputation: 6 172

Ok, so the single and double quotes instead of backslashes, got it.Tom 2018-12-06T02:17:59.127

Also, if I want to sign one key at a time, do I need to set the sighashtype param to 'SINGLE' ?Tom 2018-12-06T02:18:49.680

No, sighash is a way to specify what you actually want to sign, not the keys you want to sign with. See https://bitcoin.org/en/developer-guide#term-signature-hash

JBaczuk 2018-12-06T02:24:54.183

no problem. You could also provide the quoted json in this format (escaping the inner quotes): "[\"privkey\"]" but I find the above easier to read.JBaczuk 2018-12-06T02:28:07.573