Skip to content

Instantly share code, notes, and snippets.

@dexX7
Created October 5, 2014 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexX7/96c7ca99f909c15fad68 to your computer and use it in GitHub Desktop.
Save dexX7/96c7ca99f909c15fad68 to your computer and use it in GitHub Desktop.
Using Master Core to create a P2SH multisig wallet and send some tokens
goals:
- create a 1-of-3 script hash wallet with wallet keys
- send some tokens to the p2sh wallet
- send some tokens back
---
// let's see which addresses are availabel at all:
mastercore-cli listaddressgroupings
[
[
[
"mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
6.38768763,
""
],
[
"n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ",
3.25701731,
""
],
[
"mz5U62ZoRLF6uDYBh3QUTFLCnNEGLMoZR8",
1.33611033
]
]
]
// the public keys associated with those addresses will be used to setup the multisig wallet:
mastercore-cli validateaddress mvayzbj425X55kRLLPQiuCXWUED6LMP65C
{
"isvalid" : true,
"address" : "mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
"ismine" : true,
"isscript" : false,
"pubkey" : "0347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3",
"iscompressed" : true,
"account" : ""
}
mastercore-cli validateaddress n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ
{
"isvalid" : true,
"address" : "n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ",
"ismine" : true,
"isscript" : false,
"pubkey" : "024451fc7d9e271fab77265bd0292fc274ee231e7ecc076bf6269999c0cbbf9f90",
"iscompressed" : true,
"account" : ""
}
mastercore-cli validateaddress mz5U62ZoRLF6uDYBh3QUTFLCnNEGLMoZR8
{
"isvalid" : true,
"address" : "mz5U62ZoRLF6uDYBh3QUTFLCnNEGLMoZR8",
"ismine" : true,
"isscript" : false,
"pubkey" : "038a33cf36f0e4b116523b7bcd90e488a0295c9a40d94613c48283b4a4b84d262c",
"iscompressed" : true
}
// a wallet is created which requires 1-of-signatures signed by the private keys associated with those addresses and public keys:
mastercore-cli addmultisigaddress 1 '["0347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3","024451fc7d9e271fab77265bd0292fc274ee231e7ecc076bf6269999c0cbbf9f90","038a33cf36f0e4b116523b7bcd90e488a0295c9a40d94613c48283b4a4b84d262c"]'
2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh
// this is the wallet and tokens (or coins) can be sent there:
mastercore-cli validateaddress 2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh
{
"isvalid" : true,
"address" : "2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh",
"ismine" : true,
"isscript" : true,
"script" : "multisig",
"hex" : "51210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca321024451fc7d9e271fab77265bd0292fc274ee231e7ecc076bf6269999c0cbbf9f9021038a33cf36f0e4b116523b7bcd90e488a0295c9a40d94613c48283b4a4b84d262c53ae",
"addresses" : [
"mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
"n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ",
"mz5U62ZoRLF6uDYBh3QUTFLCnNEGLMoZR8"
],
"sigsrequired" : 1,
"account" : ""
}
// from mvayzbj425X55kRLLPQiuCXWUED6LMP65C an amount of 1.1358 TMSC is sent:
mastercore-cli send_MP mvayzbj425X55kRLLPQiuCXWUED6LMP65C 2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh 2 1.1358
3eed578966b094b8cf51e0128bca2d1ef065f722808c9db186fd435a63621e01
// this is the raw transaction:
mastercore-cli getrawtransaction 3eed578966b094b8cf51e0128bca2d1ef065f722808c9db186fd435a63621e01 1
{
"hex" : "01000000014b5f0d394284cb6f9f232943d9c09909097e6cecb3f785174bd1a415bbc7535a020000006a47304402205701ead76fe50c4f13ab695f7e263b6dfbaf43eb33fb2f34f413bf8f8905b53002207864093d9171c5f900634764406c0bed5f388760f20a2b437d19c672b7e064e101210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3ffffffff04ae020000000000004751210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca32102e2e98198c130c437664f88b5a6badb134d0198413ba24d9e6c80d9d52bb830ef52ae1e0200000000000017a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce8724020000000000001976a914643ce12b1590633077b8620316f43a9362ef18e588ac20679100000000001976a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac00000000",
"txid" : "3eed578966b094b8cf51e0128bca2d1ef065f722808c9db186fd435a63621e01",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "5a53c7bb15a4d14b1785f7b3ec6c7e090999c0d94329239f6fcb8442390d5f4b",
"vout" : 2,
"scriptSig" : {
"asm" : "304402205701ead76fe50c4f13ab695f7e263b6dfbaf43eb33fb2f34f413bf8f8905b53002207864093d9171c5f900634764406c0bed5f388760f20a2b437d19c672b7e064e101 0347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3",
"hex" : "47304402205701ead76fe50c4f13ab695f7e263b6dfbaf43eb33fb2f34f413bf8f8905b53002207864093d9171c5f900634764406c0bed5f388760f20a2b437d19c672b7e064e101210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.00000686,
"n" : 0,
"scriptPubKey" : {
"asm" : "1 0347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3 02e2e98198c130c437664f88b5a6badb134d0198413ba24d9e6c80d9d52bb830ef 2 OP_CHECKMULTISIG",
"hex" : "51210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca32102e2e98198c130c437664f88b5a6badb134d0198413ba24d9e6c80d9d52bb830ef52ae",
"reqSigs" : 1,
"type" : "multisig",
"addresses" : [
"mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
"mjQ5PmaDdDti35UibMF8bkk3nRjjuuPPNz"
]
}
},
{
"value" : 0.00000542,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_HASH160 fa9ab08b2677fc812906f037f76fdd6eb70f88ce OP_EQUAL",
"hex" : "a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce87",
"reqSigs" : 1,
"type" : "scripthash",
"addresses" : [
"2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh"
]
}
},
{
"value" : 0.00000548,
"n" : 2,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 643ce12b1590633077b8620316f43a9362ef18e5 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914643ce12b1590633077b8620316f43a9362ef18e588ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mpexoDuSkGGqvqrkrjiFng38QPkJQVFyqv"
]
}
},
{
"value" : 0.09529120,
"n" : 3,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 a54cf80a5b16182f57ceded370e9d347ba4c2816 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mvayzbj425X55kRLLPQiuCXWUED6LMP65C"
]
}
}
]
}
// because the wallet is funded with tokens, but no bitcoins, the next steps will move some as well:
mastercore-cli listunspent 0 999999 '["mvayzbj425X55kRLLPQiuCXWUED6LMP65C"]'
[
{
"txid" : "3eed578966b094b8cf51e0128bca2d1ef065f722808c9db186fd435a63621e01",
"vout" : 3,
"address" : "mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
"account" : "",
"scriptPubKey" : "76a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac",
"amount" : 0.09529120,
"confirmations" : 4
},
{
"txid" : "c1e389135efdc61dfdff86c1aebb0a218c2533546d0d628f2107a42ab7f6a331",
"vout" : 1,
"address" : "mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
"account" : "",
"scriptPubKey" : "76a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac",
"amount" : 3.12780668,
"confirmations" : 15365
},
{
"txid" : "fc87d26fb63ab3c33e9128ee115d9ad6387c8206ca6d63e19e0b4957271b2f25",
"vout" : 3,
"address" : "mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
"account" : "",
"scriptPubKey" : "76a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac",
"amount" : 3.16447199,
"confirmations" : 23411
}
]
// the choice was rather arbitrary, but note: the value of the output to spend is 3.16447199 and transfer amounts of 0.1 + 3.06347199 were chosen, so 0.0001 bitcoin go to the miners:
mastercore-cli createrawtransaction '[{"txid":"fc87d26fb63ab3c33e9128ee115d9ad6387c8206ca6d63e19e0b4957271b2f25","vout":3}]' '{"2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh":0.1,"mvayzbj425X55kRLLPQiuCXWUED6LMP65C":3.06347199}'
0100000001252f1b2757490b9ee1636dca06827c38d69a5d11ee28913ec3b33ab66fd287fc0300000000ffffffff02809698000000000017a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce87bf7c4212000000001976a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac00000000
// this signs the raw transaction:
mastercore-cli signrawtransaction 0100000001252f1b2757490b9ee1636dca06827c38d69a5d11ee28913ec3b33ab66fd287fc0300000000ffffffff02809698000000000017a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce87bf7c4212000000001976a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac00000000
{
"hex" : "0100000001252f1b2757490b9ee1636dca06827c38d69a5d11ee28913ec3b33ab66fd287fc030000006b483045022100807ee50a646980156de3cf065f7081c703c8c25ba3be69324d4c89c7d27e114d022016f802886732e2681653bbb12e7bc3f4c552ae4b67616e5c8931b7779183e75501210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3ffffffff02809698000000000017a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce87bf7c4212000000001976a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac00000000",
"complete" : true
}
// and finally push it to the network:
mastercore-cli sendrawtransaction 0100000001252f1b2757490b9ee1636dca06827c38d69a5d11ee28913ec3b33ab66fd287fc030000006b483045022100807ee50a646980156de3cf065f7081c703c8c25ba3be69324d4c89c7d27e114d022016f802886732e2681653bbb12e7bc3f4c552ae4b67616e5c8931b7779183e75501210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3ffffffff02809698000000000017a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce87bf7c4212000000001976a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac00000000
853a2156e180c70ff83fd4566a4a4b8d1c8c74df601fe43bb83ecfd8bd6a9aa3
// let's see, if it worked:
mastercore-cli getrawtransaction 853a2156e180c70ff83fd4566a4a4b8d1c8c74df601fe43bb83ecfd8bd6a9aa3 1
{
"hex" : "0100000001252f1b2757490b9ee1636dca06827c38d69a5d11ee28913ec3b33ab66fd287fc030000006b483045022100807ee50a646980156de3cf065f7081c703c8c25ba3be69324d4c89c7d27e114d022016f802886732e2681653bbb12e7bc3f4c552ae4b67616e5c8931b7779183e75501210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3ffffffff02809698000000000017a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce87bf7c4212000000001976a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac00000000",
"txid" : "853a2156e180c70ff83fd4566a4a4b8d1c8c74df601fe43bb83ecfd8bd6a9aa3",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "fc87d26fb63ab3c33e9128ee115d9ad6387c8206ca6d63e19e0b4957271b2f25",
"vout" : 3,
"scriptSig" : {
"asm" : "3045022100807ee50a646980156de3cf065f7081c703c8c25ba3be69324d4c89c7d27e114d022016f802886732e2681653bbb12e7bc3f4c552ae4b67616e5c8931b7779183e75501 0347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3",
"hex" : "483045022100807ee50a646980156de3cf065f7081c703c8c25ba3be69324d4c89c7d27e114d022016f802886732e2681653bbb12e7bc3f4c552ae4b67616e5c8931b7779183e75501210347d08029b5cbc934f6079b650c50718eab5a56d51cf6b742ec9f865a41fcfca3"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.10000000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_HASH160 fa9ab08b2677fc812906f037f76fdd6eb70f88ce OP_EQUAL",
"hex" : "a914fa9ab08b2677fc812906f037f76fdd6eb70f88ce87",
"reqSigs" : 1,
"type" : "scripthash",
"addresses" : [
"2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh"
]
}
},
{
"value" : 3.06347199,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 a54cf80a5b16182f57ceded370e9d347ba4c2816 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914a54cf80a5b16182f57ceded370e9d347ba4c281688ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mvayzbj425X55kRLLPQiuCXWUED6LMP65C"
]
}
}
]
}
// note: 3eed57 was not the bitcoin funding transaction, but the send of 1.1358 TMSC which confirmed in the meantime:
mastercore-cli gettransaction_MP 3eed578966b094b8cf51e0128bca2d1ef065f722808c9db186fd435a63621e01
{
"txid" : "3eed578966b094b8cf51e0128bca2d1ef065f722808c9db186fd435a63621e01",
"sendingaddress" : "mvayzbj425X55kRLLPQiuCXWUED6LMP65C",
"referenceaddress" : "2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh",
"ismine" : true,
"confirmations" : 8,
"fee" : 0.00010000,
"blocktime" : 1412462245,
"type" : "Simple Send",
"propertyid" : 2,
"divisible" : true,
"amount" : "1.13580000",
"valid" : true
}
// looks great, also check the balance:
mastercore-cli getbalance_MP 2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh 2
{
"balance" : "1.13580000",
"reserved" : "0.00000000"
}
// the builder was used to send some tokens back:
mastercore-cli sendrawtx_MP "2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh" "000000000000000200000000000186a0" "n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ"
error: {"code":-8,"message":"error code= -233"}
// looks like there is still no logic to select a redeemer for the first multisig package, so defining one manually is required in this case:
mastercore-cli sendrawtx_MP "2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh" "000000000000000200000000000186a0" "n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ" "n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ"
60bdf3e45cc432398b0dc6b1cb33c7bbdff4163612aacf9c519a3d5cac3878b3
// some minutes later, after the transaction confirmed:
mastercore-cli gettransaction_MP 60bdf3e45cc432398b0dc6b1cb33c7bbdff4163612aacf9c519a3d5cac3878b3
{
"txid" : "60bdf3e45cc432398b0dc6b1cb33c7bbdff4163612aacf9c519a3d5cac3878b3",
"sendingaddress" : "2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh",
"referenceaddress" : "n4EmA9R4VmxLnxu9G8yZMDxvBBha8bUtEQ",
"ismine" : true,
"confirmations" : 7,
"fee" : 0.00010000,
"blocktime" : 1412463977,
"type" : "Simple Send",
"propertyid" : 2,
"divisible" : true,
"amount" : "0.00100000",
"valid" : true
}
// just for the record a general client overview:
mastercore-cli getinfo
{
"mastercoreversion" : 1010008,
"version" : 90300,
"protocolversion" : 70002,
"walletversion" : 60000,
"balance" : 10.97947825,
"blocks" : 297401,
"timeoffset" : 0,
"connections" : 15,
"proxy" : "",
"difficulty" : 16384.00000000,
"testnet" : true,
"keypoololdest" : 1405266475,
"keypoolsize" : 101,
"paytxfee" : 0.00010000,
"relayfee" : 0.00001002,
"errors" : ""
}
// and at the very end another balance check which shows 0.001 TMSC were indeed sent back
mastercore-cli getbalance_MP 2NG6JEGKjjYcA9CLS7UZ5fFCBgYs8r737Zh 2
{
"balance" : "1.13480000",
"reserved" : "0.00000000"
}
---
eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment