Skip to content

Zcoin (2 of 2) Multisig Wallet

catchingknives edited this page Oct 18, 2018 · 1 revision

Text by @kp0z

Applications

  • Husband and wife with a savings account, both need to sign to spend fund
  • 2FA: cold sign a tx with offline wallet (pre-signed with online wallet)

Create 2-of-2 multisig address

createmultisig 2 '["aGFXRDTcZg3g1gA5e7bt9PfmxAY2QJiPDJ", "aM51F4gVkHrLiC8pS4PvVJrvzCVJfrGoZC"]'
{
  "address": "4CFa4fnAQvFz4VpikGNzQ9XfCDXMmdk6sh",
  "redeemScript": "522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52ae"
}

Double-check addresses and p2sh (pay-to-script-hash):

decodescript 522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52ae
{
  "asm": "2 02b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e204614 03440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e 2 OP_CHECKMULTISIG",
  "reqSigs": 2,
  "type": "multisig",
  "addresses": [
    "aGFXRDTcZg3g1gA5e7bt9PfmxAY2QJiPDJ", 
    "aM51F4gVkHrLiC8pS4PvVJrvzCVJfrGoZC"
  ],
  "p2sh": "4CFa4fnAQvFz4VpikGNzQ9XfCDXMmdk6sh"
}

Send fund to multisig address

Make a deposit tx to multisig address (txid 448efe72a87f63af306cc5244363df1cb790490fb25bfd348281694c6d21e226)

Note down scriptPubKey a914f010b17a9189e0f2737d71ae9790359eb5bbc13787 of 4CFa4fnAQvFz4VpikGNzQ9XfCDXMmdk6sh for later use

getrawtransaction 448efe72a87f63af306cc5244363df1cb790490fb25bfd348281694c6d21e226 1
{
  ...
  "vout": [
    {
      "value": 0.00100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 f010b17a9189e0f2737d71ae9790359eb5bbc137 OP_EQUAL",
        "hex": "a914f010b17a9189e0f2737d71ae9790359eb5bbc13787",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "4CFa4fnAQvFz4VpikGNzQ9XfCDXMmdk6sh"
        ]
      }
    }
  ]
}

Spend fund

Spend fund to a4UAt1XU1dn9GWY7Bkc3Gp1hXXJGzMVMLn

1. Create raw tx

createrawtransaction '[{"txid":"448efe72a87f63af306cc5244363df1cb790490fb25bfd348281694c6d21e226","vout":0}]' '{"a4UAt1XU1dn9GWY7Bkc3Gp1hXXJGzMVMLn":0.001}'
010000000126e2216d4c69818234fd5bb20f4990b71cdf634324c56c30af637fa872fe8e440000000000ffffffff01a0860100000000001976a914292c9afdad88c2fe1cba22d962faf403c09560d288ac00000000

2. Double-check raw tx

decoderawtransaction 010000000126e2216d4c69818234fd5bb20f4990b71cdf634324c56c30af637fa872fe8e440000000000ffffffff01a0860100000000001976a914292c9afdad88c2fe1cba22d962faf403c09560d288ac00000000
{
  "txid": "8ed5e5014a6370b6a4ed245b7ea3f06a76dcdb5fe2487ed6e14c6b56849bd384",
  "hash": "8ed5e5014a6370b6a4ed245b7ea3f06a76dcdb5fe2487ed6e14c6b56849bd384",
  "size": 85,
  "vsize": 85,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "448efe72a87f63af306cc5244363df1cb790490fb25bfd348281694c6d21e226",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 292c9afdad88c2fe1cba22d962faf403c09560d2 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914292c9afdad88c2fe1cba22d962faf403c09560d288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "a4UAt1XU1dn9GWY7Bkc3Gp1hXXJGzMVMLn"
        ]
      }
    }
  ]
}

3. Sign tx

Sign with privkey from first address aGFXRDTcZg3g1gA5e7bt9PfmxAY2QJiPDJ

signrawtransaction '010000000126e2216d4c69818234fd5bb20f4990b71cdf634324c56c30af637fa872fe8e440000000000ffffffff01a0860100000000001976a914292c9afdad88c2fe1cba22d962faf403c09560d288ac00000000' '[{"txid":"8ed5e5014a6370b6a4ed245b7ea3f06a76dcdb5fe2487ed6e14c6b56849bd384","vout":0,"scriptPubKey":"a914f010b17a9189e0f2737d71ae9790359eb5bbc13787","redeemScript":"522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52ae"}]' '["PRIVKEY_FROM_aGFXRDTcZg3g1gA5e7bt9PfmxAY2QJiPDJ"]'
{
  "hex": "010000000126e2216d4c69818234fd5bb20f4990b71cdf634324c56c30af637fa872fe8e44000000009200483045022100d1c20177ac073dfa80f4a3421e5107dd97eb43186a31ccae8a5dfed6d8bd7df902203c32bbf9103a20e8fa6732559c0e4c409698b4d281ff1760ab301040a114f4fc0147522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52aeffffffff01a0860100000000001976a914292c9afdad88c2fe1cba22d962faf403c09560d288ac00000000",
  "complete": false,
  ...
}

Sign with privkey from second address aM51F4gVkHrLiC8pS4PvVJrvzCVJfrGoZC

signrawtransaction '010000000126e2216d4c69818234fd5bb20f4990b71cdf634324c56c30af637fa872fe8e44000000009200483045022100d1c20177ac073dfa80f4a3421e5107dd97eb43186a31ccae8a5dfed6d8bd7df902203c32bbf9103a20e8fa6732559c0e4c409698b4d281ff1760ab301040a114f4fc0147522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52aeffffffff01a0860100000000001976a914292c9afdad88c2fe1cba22d962faf403c09560d288ac00000000' '[{"txid":"8ed5e5014a6370b6a4ed245b7ea3f06a76dcdb5fe2487ed6e14c6b56849bd384","vout":0,"scriptPubKey":"a914f010b17a9189e0f2737d71ae9790359eb5bbc13787","redeemScript":"522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52ae"}]' '["PRIVKEY_FROM_aM51F4gVkHrLiC8pS4PvVJrvzCVJfrGoZC"]'
{
  "hex": "010000000126e2216d4c69818234fd5bb20f4990b71cdf634324c56c30af637fa872fe8e4400000000da00483045022100d1c20177ac073dfa80f4a3421e5107dd97eb43186a31ccae8a5dfed6d8bd7df902203c32bbf9103a20e8fa6732559c0e4c409698b4d281ff1760ab301040a114f4fc0147304402206a748c526dc1018254c4949958c816587ade484cf7e00ba2de7606a076fdf9780220754bbd937ece2b342d6c661e22265051c5fd24aa83134db53b364cf7c5ca9b510147522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52aeffffffff01a0860100000000001976a914292c9afdad88c2fe1cba22d962faf403c09560d288ac00000000",
  "complete": true
}

4. Broadcast to network

sendrawtransaction 010000000126e2216d4c69818234fd5bb20f4990b71cdf634324c56c30af637fa872fe8e4400000000da00483045022100d1c20177ac073dfa80f4a3421e5107dd97eb43186a31ccae8a5dfed6d8bd7df902203c32bbf9103a20e8fa6732559c0e4c409698b4d281ff1760ab301040a114f4fc0147304402206a748c526dc1018254c4949958c816587ade484cf7e00ba2de7606a076fdf9780220754bbd937ece2b342d6c661e22265051c5fd24aa83134db53b364cf7c5ca9b510147522102b11ba55de08319a5896591fe797ff0b607ee3a540205eb78e13e00704e2046142103440f8531f6a4dd333e89cc0882a6d7772c5c4567fe240042adda6be4ad24242e52aeffffffff01a0860100000000001976a914292c9afdad88c2fe1cba22d962faf403c09560d288ac00000000
28efb3a210f67a5103076e486dea5dec3d8ce7c5152cbf555e67b5435bc70cd6

5. Result

See 28efb3a210f67a5103076e486dea5dec3d8ce7c5152cbf555e67b5435bc70cd6

Clone this wiki locally