<p>if you are on testnet/regtest, it is completely ok, to provide "correct" data (no need for masquerading). There is the famous <a href="https://gist.github.com/gavinandresen/3966071" rel="nofollow noreferrer">2-of-3 multisig from Gavin</a>, which provides a step by step approach using RPC. This should give you the idea behind. </p>

<p>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.</p>

CC BY-SA 4.0
2018-06-15T09:39:49.967Z
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
CC BY-SA 4.0
2018-06-15T09:58:15.333Z
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
CC BY-SA 4.0
2018-06-15T19:16:04.523Z
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
CC BY-SA 4.0
2018-06-18T13:56:15.283Z
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
CC BY-SA 4.0
2018-06-18T14:24:14.657Z
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
CC BY-SA 4.0
2018-06-18T21:40:00.137Z
(Well, more precisely transactions don’t have funds... but the tx shown by blockchain.conf has funds associated with the addresses shown)
pebwindkraft
CC BY-SA 4.0
2018-06-19T08:21:40.407Z
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
CC BY-SA 4.0
2018-06-15T09:12:59.383Z
2018-06-15T09:12:59.383Z
pebwindkraft
<p>I´m trying to build a multisig transaction using RPC. Till now my code looks similar to this:</p>

<p>At first I get the unspend outputs calling <code>listunspend()</code></p>

<p>With those UTXOs I´ll try to create the rawtransaction:</p>

<pre><code>createrawtransaction
'[
{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0117","vout":0},
{"txid":"03a4ffcc792525b4ddaecc05054114f2ad8aff8b7563cd41cdb496e2177d0116","vout":0}
]' 
'{"mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf":0.05}'
</code></pre>

<p>The result of this call I use for signing:</p>

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

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

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

<p><strong>UPDATE:</strong></p>

<p>Latest unsigned raw transaction in BTC live net:</p>

<pre><code>020000000195b96fa7fff141564feba34cb669bdeb94953c98ae864465623def3fbe9e9fb10100000000ffffffff01e87a0100000000001976a914d05bddfbc9059d06168b7bf08bd20d5f1fdaf79588ac00000000
</code></pre>

<json-rpc>
building a multisig transaction using RPC
Michael
# building a multisig transaction using RPC

(Asked by: username_0 on 2018-06-15)

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

```

**Tags:** json-rpc


---

## 1 answers

### Answer by username_1 on 2018-06-15. Score: 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](https://gist.github.com/gavinandresen/3966071), 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.

> **Comments:**
> **username_0**: 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?  
> **username_0**: 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?  
> **username_1**: 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...  
> **username_0**: 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?  
> **username_1**: 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"?  
> **username_1**: (Well, more precisely transactions don’t have funds... but the tx shown by blockchain.conf has funds associated with the addresses shown)  
> **username_0**: 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)  

---

