Skip to content

Instantly share code, notes, and snippets.

@matiu
Created April 22, 2014 15:10
Show Gist options
  • Save matiu/11182987 to your computer and use it in GitHub Desktop.
Save matiu/11182987 to your computer and use it in GitHub Desktop.
Creating and testing p2sh multisig bitcoin transactions
$bitcoind getinfo
{
"version" : 99900,
"protocolversion" : 70002,
"walletversion" : 60000,
"balance" : 15.74900000,
"blocks" : 226032,
"timeoffset" : -4,
"connections" : 9,
"proxy" : "",
"difficulty" : 1.00000000,
"testnet" : true,
"keypoololdest" : 1396356989,
"keypoolsize" : 101,
"paytxfee" : 0.00000000,
"relayfee" : 0.00001000,
"errors" : "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
}
$ bitcoind createmultisig 2 '["03197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d", "0392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed03", "03e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e4"]'
{
"address" : "2NFW3ja1tdza4b1WTyG9fkz6cBtRf4qEFBh",
"redeemScript" : "522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae"
}
$ bitcoind createrawtransaction '[{"txid":"2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1","vout":1,"scriptPubKey":"2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1","redeemScript":"522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae"}]' '{"mon1Hqs3jqKTtRSnRwJ3pRYMFos9WYfKb5":0.08}'
0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a0100000000ffffffff0100127a00000000001976a9145a99bf375234ca261aff6a3f11613617369d02c788ac00000000
// PARTIALLY SIGN IT
$ bitcoind signrawtransaction '0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a0100000000ffffffff0100127a00000000001976a9145a99bf375234ca261aff6a3f11613617369d02c788ac00000000' '[{"txid":"2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1","vout":1,"scriptPubKey":"a914f4207283b5a7bce7672a88bcef4580ea0b6aed9687","redeemScript":"522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae"}]' '["cMpKwGr5oxEacN95WFKNEq6tTcvi11regFwS3muHvGYVxMPJX8JA"]'
{
"hex" : "0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a01000000b500483045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b014c69522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453aeffffffff0100127a00000000001976a9145a99bf375234ca261aff6a3f11613617369d02c788ac00000000",
"complete" : false
}
// ADD OTHER SIGNATURE AND COMPLETE IT
$ bitcoind signrawtransaction '0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a01000000b500483045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b014c69522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453aeffffffff0100127a00000000001976a9145a99bf375234ca261aff6a3f11613617369d02c788ac00000000' '[{"txid":"2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1","vout":1,"scriptPubKey":"a914f4207283b5a7bce7672a88bcef4580ea0b6aed9687","redeemScript":"522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae"}]' '["cVf32m9MR4vxcPwKNJuPepUe8XrHD2z63eCk76d6njRGyCkXpkSM"]'
{
"hex" : "0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a01000000fdfe0000483045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b01483045022100a505aff6a1d9cc14d0658a99ebcf1901b5c9f9e6408055fa9b9da443c80bfdb602207f0391c98abecc93bc3b353c55ada4d3fb6d4bab48fd63ae184df1af367cee46014c69522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453aeffffffff0100127a00000000001976a9145a99bf375234ca261aff6a3f11613617369d02c788ac00000000",
"complete" : true
}
// How partially signed transaction looks like:
$ bitcoin decoderawtransaction 0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a01000000b500483045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b014c69522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453aeffffffff0100127a00000000001976a9145a99bf375234ca261aff6a3f11613617369d02c788ac00000000
{
"txid" : "bdf17aba74d69983420e3a4854e4237755c14122e6fe98e58eb9ca9fdc1f5057",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
"vout" : 1,
"scriptSig" : {
"asm" : "0 3045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b01 522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae",
"hex" : "00483045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b014c69522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.08000000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 5a99bf375234ca261aff6a3f11613617369d02c7 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a9145a99bf375234ca261aff6a3f11613617369d02c788ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mon1Hqs3jqKTtRSnRwJ3pRYMFos9WYfKb5"
]
}
}
]
}
// and its scriptSig
$ bitcoind decodescript 00483045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b014c69522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae
{
"asm" : "0 3045022100aac57f3ba004e6265097b759d92132c43fb5dcb033c2a3f6e61caa5e05e6b97e02200dae579e54c8e733d222eae5bbbaf557bbcf03271cf76775c91744c24a99916b01 522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae",
"type" : "nonstandard",
"p2sh" : "2NAVTeGHGEb2qKeti525GJALMfHjqPj3EJZ"
}
// and its redeem script
$ bitcoind decodescript 522103197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d210392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed032103e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e453ae
{
"asm" : "2 03197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d 0392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed03 03e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e4 3 OP_CHECKMULTISIG",
"reqSigs" : 2,
"type" : "multisig",
"addresses" : [
"mgwqzy6pF5BSc72vxHBFSnnhNEBcV4TJzV",
"n3FSx13BMjMYXNxT8m2kJZiAZH1tNkm1tv",
"mwjgtj2ZQAA7KXYizDoKwud3ghUyoFqqGZ"
],
"p2sh" : "2NFW3ja1tdza4b1WTyG9fkz6cBtRf4qEFBh"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment