比特币(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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。