单机环境regtest 测试
- 准备好3个地址及其公钥私钥
地址 n1GwLVa9VgynhKSCZksHs5RmrWuuNyhz4E
公钥 02f8746b23e90fc7dfdfce8bf4213e0091632d380183beb66176586570178d1e65
私钥 cSoGgSUPGrnwFFA4WBZoqpoa91KLwZDjKq3Yk5AHWfgTpraxCeS4
地址 mgtz63xGHPoKkaedD5E7x6jEQDqbveQdPo
公钥 028d9b59c15f1fa7e9324330a412ab4a36acd4caea06fd9eba4274b0bcd492815b
私钥 cNbpffkRTeUAhxfwKS1e3zf2NcuozdW4eDGmue6vD1Fqbt1vTav6
地址 n3QP94dgczRU4MrzsSEKzrHHrUzwiFRjVs
公钥 03520e6e05f71f72ad760a50a071971299fa5ff7b8b4ba0c5ce52b6c53e2866f9a
私钥 cU9m7U9PQuTNfxC8wRh8zcyUXNKijasAGr9ybuXuGRZ6EUdxA6wx
- 使用公钥创建多签地址:
createmultisig
这里使用 2 of 3 的模式
freecash-cli -regtest createmultisig 2 '["02f8746b23e90fc7dfdfce8bf4213e0091632d380183beb66176586570178d1e65","028d9b59c15f1fa7e9324330a412ab4a36acd4caea06fd9eba4274b0bcd492815b","03520e6e05f71f72ad760a50a071971299fa5ff7b8b4ba0c5ce52b6c53e2866f9a"]'
得到输出:
{
"address": "2N5GYr5aWGHv1enu2DeqvP3nX7ky6NieDL8",
"redeemScript": "522102f8746b23e90fc7dfdfce8bf4213e0091632d380183beb66176586570178d1e6521028d9b59c15f1fa7e9324330a412ab4a36acd4caea06fd9eba4274b0bcd492815b2103520e6e05f71f72ad760a50a071971299fa5ff7b8b4ba0c5ce52b6c53e2866f9a53ae"
}
添加多签地址到钱包
addmultisigaddress
freecash-cli -regtest addmultisigaddress 2 '["02f8746b23e90fc7dfdfce8bf4213e0091632d380183beb66176586570178d1e65","028d9b59c15f1fa7e9324330a412ab4a36acd4caea06fd9eba4274b0bcd492815b","03520e6e05f71f72ad760a50a071971299fa5ff7b8b4ba0c5ce52b6c53e2866f9a"]'
- 启动freecash 使用单机模式
freecashd -regtest -daemon
挖一些币
freecash-cli -regtest generate 101
给刚刚那个多签地址发10FCH
freecash-cli -regtest sendtoaddress 2N5GYr5aWGHv1enu2DeqvP3nX7ky6NieDL8 10.00
得到返回txid = 407e6f37640770541b8a7950c8d139acddb23a01541fdb10c3afe70e25331c57
使其生效
freecash-cli -regtest generate 1
- 从多重签名地址付款
2 of 3的模式,就是说,三个管理者中,持有任意两人的私钥便可付款,我们这个多签地址刚刚的金额是10,就随便给另外一个地址发9.9吧。
先创建交易
freecash-cli -regtest createrawtransaction '[{"txid":"407e6f37640770541b8a7950c8d139acddb23a01541fdb10c3afe70e25331c57","vout":0}]' '{"n1VAs96DPUmTXv1qmu6q3VhdCDSJFzQxKp":9.99}'
输出:
0200000001571c33250ee7afc310db1f54013ab2ddac39d1c850798a1b54700764376f7e400000000000ffffffff01c0878b3b000000001976a914db0c2d5258555e1a0d8bd61894956bca1b9f6f7488ac00000000
用2私钥对交易单签名:
命令的第1个参数,就是createrawtransaction的输出。
第2个参数,是使用的2个私钥。
第3个参数,关于tx的参数,txid vout scriptPubKey amount 从输入的tx获得,redeemScript 是你创建多签地址createmultisig的返回。
freecash-cli -regtest signrawtransactionwithkey 0200000001571c33250ee7afc310db1f54013ab2ddac39d1c850798a1b54700764376f7e400000000000ffffffff01c0878b3b000000001976a914db0c2d5258555e1a0d8bd61894956bca1b9f6f7488ac00000000 '["cSoGgSUPGrnwFFA4WBZoqpoa91KLwZDjKq3Yk5AHWfgTpraxCeS4","cU9m7U9PQuTNfxC8wRh8zcyUXNKijasAGr9ybuXuGRZ6EUdxA6wx"]' '[{"txid":"407e6f37640770541b8a7950c8d139acddb23a01541fdb10c3afe70e25331c57","vout":0,"scriptPubKey":"a91483e1aaedc04897682f69156cec746297106cad6487","redeemScript": "522102f8746b23e90fc7dfdfce8bf4213e0091632d380183beb66176586570178d1e6521028d9b59c15f1fa7e9324330a412ab4a36acd4caea06fd9eba4274b0bcd492815b2103520e6e05f71f72ad760a50a071971299fa5ff7b8b4ba0c5ce52b6c53e2866f9a53ae","amount":10}]'
将得到返回:
"complete": true 表示成功
(2of3模式,如果你只传一个私钥,会报错“possibly missing key”)
再去send
freecash-cli -regtest sendrawtransaction 刚刚多签的返回