[BTC]bitcoin-cli完成一个支付流程

偶尔临时要做些测试,需要最原生的命令。在这里做个记录,可能有的人以后会需要用到。

1.首先要找到一个可花费交易ID

bitcoin-cli listunspent 0
0是指最低需要多少个确认的可花费交易,一般填1。

返回:
{
"txid": "b95295525022af2b757cf1a65a477928e52ea0ebe71111111111111111",
"vout": 2,
"address": "1EvCft26Vuzxcn9pX537475DVV7m8k9wB8",
"account": "nghiemvo-panda-miner",
"scriptPubKey": "76a91498a96c4e71ad6a3b22709a8797e9749455133bf988ac",
"amount": 0.59000000,
"confirmations": 441,
"spendable": true,
"solvable": true
},

2.根据TX和VOUT创建一个原生交易

bitcoin-cli createrawtransaction '[{"txid":"b95295525022af2b757cf1a65a477928e52ea0ebe71111111111111111","vout":2}]' '{"1PiYV7uxFVMJj6C6wm91gBN4P3FFFwFhqG":4.999}'

返回:
0100000001cb4f83704de66fc0c9a8d5b2f3fa12bca43f2fb642910ec81c0990d87baa075a0000000000ffffffff01c0320a03000000001976a914f92e1a97926d8e965291b486efb2116e7c5471f088ac11111

3.对这个交易进行签名

bitcoin-cli signrawtransaction 0100000001cb4f83704de66fc0c9a8d5b2f3fa12bca43f2fb642910ec81c0990d87baa075a0000000000ffffffff01c0320a03000000001976a914f92e1a97926d8e965291b486efb2116e7c5471f088ac11111

返回:
{
"hex": "0100000001feea1cb9cf5970883e3e5700c0d9497c76ee1031b22c39f6365168edd38870d3010000006a473044022072b723202bf793fef13e3c6bcf3d9fcfdb1052b671d42f969835d843820c76b6022072402c9bc9a479c2dc1ee0411c4888c86a63413ba537ce8fc10690a69033add4012103678afd6819e63fc6add7d1ea80c19dcf7ee113a7afc30f6fe4c461ebb5597972ffffffff0160decb1d000000001976a914f92e1a97926d8e965291b486efb2116e7c5471f088ac00000000",
"complete": true
}

4.向区块广播这笔交易

bitcoin-cli sendrawtransaction 0100000001feea1cb9cf5970883e3e5700c0d9497c76ee1031b22c39f6365168edd38870d3010000006a473044022072b723202bf793fef13e3c6bcf3d9fcfdb1052b671d42f969835d843820c76b6022072402c9bc9a479c2dc1ee0411c4888c86a63413ba537ce8fc10690a69033add4012103678afd6819e63fc6add7d1ea80c19dcf7ee113a7afc30f6fe4c461ebb5597972ffffffff0160decb1d000000001976a914f92e1a97926d8e965291b486efb2116e7c5471f088ac00000000

返回TX:
25604bb691a001e6b580bed61e5880ca283db805188589eac825ddf73f098eed

5.完毕,等待区块确认。

你可能感兴趣的:([BTC]bitcoin-cli完成一个支付流程)