How to make a 1-of-2 multisig transaction

The following will contain a tutorial on how to create a 1 of 2 multisig address, spend some coins to it, and then transfer them back again to a regular adddress. While you can and should look at the given tx id’s in the block explorer, this recipe is definitely not fool proof. Hopefully a script can do this in the future. It is advisable to attempt this first, with a very small amount of coins, or best on testnet. Either pass in the following commands to the daemon, or to the debug console on the gui client, found in Help -> Debug window -> Console. I will walk through this example with keys I generated, so the values will change, if you try it yourself.

For this process we will first generate two public keys. In practice these would be generated by each of the two participants.

getnewpubkey

>>> 0373e24548faf74d868302d201be50fb3674cfa698e5871589e92cb53c906b9f80

getnewpubkey

>>> 0264637aa8489febaeb394d28f3fa73da546c6e9e3c576d5156876745e452c4c83

Then generate a multisigaddress with these two public keys using addmultisigaddress. The number after the addmultisigaddress command is the number of required signatures to be able to spend from the address. The output is the new multisigaddress:

addmultisigaddress 1 '["0373e24548faf74d868302d201be50fb3674cfa698e5871589e92cb53c906b9f80",
    "0264637aa8489febaeb394d28f3fa73da546c6e9e3c576d5156876745e452c4c83"]'

>>> bE9beycFciNiykheLUmSPn5txcsvAMvA8v

Next extract the redeemScript of the address with validateaddress:

validateaddress bE9beycFciNiykheLUmSPn5txcsvAMvA8v

>>>{... "hex" : "51210373e24548faf74d868302d201be50fb3674cfa698e5871589e92cb53c906b9f80210264637aa8489febaeb394d28f3fa73da546c6e9e3c576d5156876745e452c4c8352ae", ... }

We need this hex string for the transaction spending from the multisig again. You can either send coins manually to the multisigaddress, or generate your own transaction. To do this execute listunspent . This shows you all the addresses you can spend from. In this guide we will assume, that you want to transfer all the coins a single address is holding. At the time of writing I had the following address in my wallet:

"txid": 79d453fe1decdab1948c9e48f068267da3aada8a5b01f0afede7849e0f0596fa
"vout": 0
"address": RxscZLCm17ms4sbGyASP7bCk5f1Fe7em9A
"amount": 0.98

Keep hold of these values from the transaction you have chosen. Then generate a rawtransaction. The difference in amount between the rawtransaction and the input transaction will be left as a transaction fee and spent to the miner. We use the txid and index number of outputs of the chosen address as input arguments.

createrawtransaction '[{"txid":"79d453fe1decdab1948c9e48f068267da3aada8a5b01f0afede7849e0f0596fa","vout":0}]'  
    '{"bE9beycFciNiykheLUmSPn5txcsvAMvA8v":0.97}'

>>> 01000000f6c1ad5901fa96050f9e84e7edaff0015b8adaaaa37d2668f0489e8c94b1daec1dfe53d4790000000000ffffffff01401ac8050000000017a9140f91efd3fe4dc089c6e2f4e259705f3a37716733870000000000

Since we only spend 0.97 and the input was 0.98, the transaction fee will be 0.01 GRC. Then sign the transaction:

signrawtransaction 01000000f6c1ad5901fa96050f9e84e7edaff0015b8adaaaa37d2668f0489e8c94b1daec1dfe53d4790000000000ffffffff01401ac8050000000017a9140f91efd3fe4dc089c6e2f4e259705f3a37716733870000000000

>>> 01000000f6c1ad5901fa96050f9e84e7edaff0015b8adaaaa37d2668f0489e8c94b1daec1dfe53d479000000006b483045022100886589c4ba4d156f269f2b7dd20f0910a0ce4131e415b9f560b81abd6d6cbcb9022048898b4962ca173a9a84faa695ada534a9f974f03b42ad8905d2b0fd857a60a00121030bc01f209c80231c42afc9c24e2e8078945ebd9c588dfe0748e14aca09a58255ffffffff01401ac8050000000017a9140f91efd3fe4dc089c6e2f4e259705f3a37716733870000000000

The signed transaction script is then decoded to get the scriptPubKey

decoderawtransaction 01000000f6c1ad5901fa96050f9e84e7edaff0015b8adaaaa37d2668f0489e8c94b1daec1dfe53d479000000006b483045022100886589c4ba4d156f269f2b7dd20f0910a0ce4131e415b9f560b81abd6d6cbcb9022048898b4962ca173a9a84faa695ada534a9f974f03b42ad8905d2b0fd857a60a00121030bc01f209c80231c42afc9c24e2e8078945ebd9c588dfe0748e14aca09a58255ffffffff01401ac8050000000017a9140f91efd3fe4dc089c6e2f4e259705f3a37716733870000000000

>>> {
"txid" : "37ea71fdc4af9a3248b3a6a4e4048c00e588827319a1f04d6bf237038848fcd3",
...
"vout" : [
{
"value" : 0.97000000,
"n" : 0,
"scriptPubKey" : {
"hex" : "a9140f91efd3fe4dc089c6e2f4e259705f3a3771673387",
"addresses" : [
"bE9beycFciNiykheLUmSPn5txcsvAMvA8v"
]}}]}

From this output we need the title txid, the index of the output n, the scriptPubkey in hexadecimal andour multisigaddress. If you have followed so far with the tutorial, check again, that you are in actual possession of the keypairs you have generated you unique multisigaddress with. Then send the transaction to the network:

sendrawtransaction 01000000f6c1ad5901fa96050f9e84e7edaff0015b8adaaaa37d2668f0489e8c94b1daec1dfe53d479000000006b483045022100886589c4ba4d156f269f2b7dd20f0910a0ce4131e415b9f560b81abd6d6cbcb9022048898b4962ca173a9a84faa695ada534a9f974f03b42ad8905d2b0fd857a60a00121030bc01f209c80231c42afc9c24e2e8078945ebd9c588dfe0748e14aca09a58255ffffffff01401ac8050000000017a9140f91efd3fe4dc089c6e2f4e259705f3a37716733870000000000

>>> 37ea71fdc4af9a3248b3a6a4e4048c00e588827319a1f04d6bf237038848fcd3

This should be the same “txid” as in the decoderawtransaction output. You now have your chosen amount on the multisigaddress. Next generate a new address either from the “Receive” pane in the wallet (preferred way), or from the command line:

getnewaddress

>>> SFBBaFognXQxaiKc9bNaR7Vw3gWvN1aGJ1

This address will be used to receive the funds from the multisigaddress. We create another rawtransaction for this:

createrawtransaction '[{"txid":"37ea71fdc4af9a3248b3a6a4e4048c00e588827319a1f04d6bf237038848fcd3","vout":0, 
    "scriptPubKey":"a9140f91efd3fe4dc089c6e2f4e259705f3a3771673387",
    "redeemScript":"5121027e3b0c06da9ae98f9ab6e145161fd3e877b472a8f3ec3fdcdcd1f6141ef09b14210256d7539a6d42b97a9f7da020ab0ca4ed62f5e48e286f8f57ae8de3b8c6c1318a52ae"}]' 
    '{"SFBBaFognXQxaiKc9bNaR7Vw3gWvN1aGJ1":0.96}'

>>> 01000000f0c7ad5901d3fc48880337f26b4df0a119738288e5008c04e4a4a6b348329aafc4fd71ea370000000000ffffffff0100d8b805000000001976a914bce5221dfef9ac624dce1d1e8f02c898997cab8488ac0000000000
     

We use the transaction id of the transaction funding the multisigaddress, and its scriptPubkey. The redeem script is the one that was extracted from the multisig address with validateaddress. We again leave 0.01 GRC as fee for the miner. Finally execute `signrawtransaction again on the raw transaction script:

signrawtransaction 01000000f0c7ad5901d3fc48880337f26b4df0a119738288e5008c04e4a4a6b348329aafc4fd71ea370000000000ffffffff0100d8b805000000001976a914bce5221dfef9ac624dce1d1e8f02c898997cab8488ac0000000000

01000000f0c7ad5901d3fc48880337f26b4df0a119738288e5008c04e4a4a6b348329aafc4fd71ea3700000000920048304502210084a47d7882fe23fd6b2d854fe1047ffb3b5b809a9bd25762bcbf8002832fb2c60220374e40bc6c934abcf3c13b01d6d8eb1c30da6e07816131a46372ec6edff849f9014751210373e24548faf74d868302d201be50fb3674cfa698e5871589e92cb53c906b9f80210264637aa8489febaeb394d28f3fa73da546c6e9e3c576d5156876745e452c4c8352aeffffffff0100d8b805000000001976a914bce5221dfef9ac624dce1d1e8f02c898997cab8488ac0000000000

Then send the transaction to the network:

sendrawtransaction 01000000f0c7ad5901d3fc48880337f26b4df0a119738288e5008c04e4a4a6b348329aafc4fd71ea3700000000920048304502210084a47d7882fe23fd6b2d854fe1047ffb3b5b809a9bd25762bcbf8002832fb2c60220374e40bc6c934abcf3c13b01d6d8eb1c30da6e07816131a46372ec6edff849f9014751210373e24548faf74d868302d201be50fb3674cfa698e5871589e92cb53c906b9f80210264637aa8489febaeb394d28f3fa73da546c6e9e3c576d5156876745e452c4c8352aeffffffff0100d8b805000000001976a914bce5221dfef9ac624dce1d1e8f02c898997cab8488ac0000000000

>>> 4003e83ce381b8a6b7953954b7d346158957f5c66191e77a730aab9a480c238c

And done. You now have the coins back in an address from which only you can spend from.

Written on September 3, 2017