比特幣(Bitcoin) RPC Rawtransactions API中signrawtransactionwithkey的用法及代碼示例。
用法:
signrawtransactionwithkey "hexstring" ["privatekey",...] ( [{"txid":"hex","vout":n,"scriptPubKey":"hex","redeemScript":"hex","witnessScript":"hex","amount":amount},...] "sighashtype" )
簽署原始交易的輸入(序列化,hex-encoded)。
第二個參數是一個以base58編碼的私鑰數組,它將是用於簽署交易的唯一 key 。
第三個可選參數(可以為null)是此事務所依賴的先前事務輸出的數組,但可能尚未出現在區塊鏈中。
參數1 - hexstring
類型:字符串,必填
交易十六進製字符串
參數2 - privkeys
類型:json數組,必需
用於簽名的base58編碼私鑰的json數組
[
"privatekey", (string) private key in base58-encoding
...
]
參數3 - prevtxs
類型:json數組,可選
先前相關交易輸出的json數組
[
{ (json object)
"txid": "hex", (string, required) The transaction id
"vout": n, (numeric, required) The output number
"scriptPubKey": "hex", (string, required) script key
"redeemScript": "hex", (string) (required for P2SH) redeem script
"witnessScript": "hex", (string) (required for P2WSH or P2SH-P2WSH) witness script
"amount": amount, (numeric or string, required) The amount spent
},
...
]
參數4 - sighashtype
類型:字符串,可選,默認= ALL
- 簽名哈希類型。必須是以下之一:
“ALL” “NONE” “SINGLE” “ALL|ANYONECANPAY” “NONE|ANYONECANPAY” “SINGLE|ANYONECANPAY”
返回結果
{
"hex" : "value", (string) The hex-encoded raw transaction with signature(s)
"complete" : true|false, (boolean) If the transaction has a complete set of signatures
"errors" : [ (json array of objects) Script verification errors (if there are any)
{
"txid" : "hash", (string) The hash of the referenced, previous transaction
"vout" : n, (numeric) The index of the output to spent and used as input
"scriptSig" : "hex", (string) The hex-encoded signature script
"sequence" : n, (numeric) Script sequence number
"error" : "text" (string) Verification or signing error related to the input
}
,...
]
}
示例
bitcoin-cli signrawtransactionwithkey "myhex"
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "signrawtransactionwithkey", "params": ["myhex"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
相關用法
- Bitcoin analyzepsbt用法及代碼示例
- Bitcoin combinepsbt用法及代碼示例
- Bitcoin combinerawtransaction用法及代碼示例
- Bitcoin converttopsbt用法及代碼示例
- Bitcoin createpsbt用法及代碼示例
- Bitcoin createrawtransaction用法及代碼示例
- Bitcoin decodepsbt用法及代碼示例
- Bitcoin decoderawtransaction用法及代碼示例
- Bitcoin decodescript用法及代碼示例
- Bitcoin finalizepsbt用法及代碼示例
- Bitcoin fundrawtransaction用法及代碼示例
- Bitcoin getrawtransaction用法及代碼示例
- Bitcoin joinpsbts用法及代碼示例
- Bitcoin sendrawtransaction用法及代碼示例
- Bitcoin testmempoolaccept用法及代碼示例
- Bitcoin utxoupdatepsbt用法及代碼示例
注:本文由純淨天空篩選整理自bitcoin.org大神的英文原創作品 Bitcoin signrawtransactionwithkey。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。