building a multisig transaction using RPC

0

I´m trying to build a multisig transaction using RPC. Till now my code looks similar to this:

At first I get the unspend outputs calling listunspend()

With those UTXOs I´ll try to create the rawtransaction:

createrawtransaction
'[
{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0},
{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0116","vout":0}
]' 
'{"mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf":0.05}'

The result of this call I use for signing:

signrawtransaction 
020000000117017d17e296b4cd41cd63758bff8aadf214410505ccaeddb4252579ccffa4030000000000ffffffff0100b4c404000000001976a914ac19d3fd17710e6b9a331022fe92c693fdf6659588ac00000000 
'[
    {"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0,"scriptPubKey":"a91421ce1507d06ed2742be0bf18a018bbcdd812a26487","redeemScript":"00149835f2e0dff9d7f6a4060140696bc7e00b12edd5"},
    {"txid":"13a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0116","vout":0,"scriptPubKey":"b91421ce1507d06ed2742be0bf18a018bbcdd812a26486","redeemScript":"10149835f2e0dff9d7f6a4060140696bc7e00b12edd6"}
]' 
'["cMahea7zqjxryy6NWaKxmhDyb1JzuNKCZAg8sxaJoXSBkRXjnib9"]'

At this point I get the error Missing amount and I can´t figure out why. I´m not sure which values to use for the signrawtransaction() call. Should I use the same txid and vout values as for the createrawtransaction? Where do I get the correct scriptPubKey and redeemScript values from?

Note: the provided txid´s and addresses are only samples (maybe not valid) and not the ones I´m using for my code.

UPDATE:

Latest unsigned raw transaction in BTC live net:

020000000195b96fa7fff141564feba34cb669bdeb94953c98ae864465623def3fbe9e9fb10100000000ffffffff01e87a0100000000001976a914d05bddfbc9059d06168b7bf08bd20d5f1fdaf79588ac00000000

Michael

Posted 2018-06-15T08:31:50.117

Reputation: 111

Answers

1

if you are on testnet/regtest, it is completely ok, to provide "correct" data (no need for masquerading). There is the famous 2-of-3 multisig from Gavin, which provides a step by step approach using RPC. This should give you the idea behind.

Generally you are correct, you would search for listunspents, take one of the transaction numbers, and see in the transaction, which unspent output you can use (usually it is a 0 or 1 for the first or second). And for sure this transaction should have some amount, that you can spend. Use "decoderawtransaction" to see the details of the tx. When you have created the tx with "createrawtransaction", then it returns a string of data, that can be used as parameter to the "sign" call.

pebwindkraft

Posted 2018-06-15T08:31:50.117

Reputation: 4 568

Thanks for the link, I´ll go through it. decoding my rawtransaction it should have an amount, but this amount (why ever) seems not to be available while performing the signrawtransaction process. And my question would still be Where do I get the correct scriptPubKey and redeemScript values from? to correctly perform the signing step?Michael 2018-06-15T09:39:49.967

After reading parts of the linked source it gets a bit clearer how multisig addresses seem to work. So the redeemScript seems to be the one of the initial multisigaddress. you know if there is any way to recover this data while only haveing access to 2 of the 3 private keys?Michael 2018-06-15T09:58:15.333

Basically you have three steps: 1) create redeemscript and address, 2) fund this address; 3) spend from this address. The redeemscript is created out of three public keys. The "createmultisig" call would be provided with the parameters, and returns a hash of it (which is the new multi-sig address). And this hash is not reversible. So if you created such a multisig address, and lost the corresponding keys, you cannot easily re-create it. With highly sophisticated knowledge and effort, you could go through all the keys of involved wallet(s), and create appropriate combinations manually...pebwindkraft 2018-06-15T19:16:04.523

after reading the guide I still get an error while trying to sign the rawtransaction. The decoded rawtransacion looks fine but while I try to sign it I get "Missing amount" even if in the decoded raw transaction the correct amount is displayed. For my approach I use the folling parameter: signrawtransaction([hex_from_createrawtransaction], [inputs_used_for_createrawtransaction(txid, vout, scriptPubKey, redeemScript)],[one_privateKey]). Anything wrong or missing?Michael 2018-06-18T13:56:15.283

I try to follow each step: I looked up the tx, that you want to spend from - the second line in the signrawtransaction example above. This tx ID cannot be found on testnet. Same for the tx ending with "116" in createtransaction (testnet.blockchain.info). Only the tx ending with "117" has funds on it. The numbers in the (second) lines seem to be "to close", they are just incremented by 1 at specific positions - it might be correct, but I haven't seen this before. Can you try to go with a single input and output, using only the tx ending with "117"?pebwindkraft 2018-06-18T14:24:14.657

(Well, more precisely transactions don’t have funds... but the tx shown by blockchain.conf has funds associated with the addresses shown)pebwindkraft 2018-06-18T21:40:00.137

Thanks for the help. As told in the OP the txids (...) only have been samples from a tutorial I started with. I´ve updated the OP with a unsigned raw transaction from the live net. Aufter the first signing step it tells me "Operation not valid with the current stack size" which seems to be okay for a multisig tx, the second signing tells me "Signature must be zero for failed CHECK(MULTI)SIG operation" (no matter which of the 3 private keys i use for the first or second signing step)Michael 2018-06-19T08:21:40.407