比特幣(Bitcoin) RPC Rawtransactions API中fundrawtransaction的用法及代碼示例。
用法:
fundrawtransaction "hexstring" ( options iswitness )
向交易添加輸入,直到其價值足以滿足其超出價值為止。
這不會修改現有的輸入,並且最多會將一個更改輸出添加到輸出中。
除非指定了“subtractFeeFromOutputs”,否則不會修改現有的輸出。
請注意,已簽名的輸入可能需要在完成後重新簽名,因為已添加了in /outputs。
- 添加的輸入將不會被簽名,請使用signrawtransactionwithkey
或為此簽署signrawtransactionwithwallet。
請注意,所有現有輸入都必須將其先前的輸出事務保存在電子錢包中。
請注意,所有選擇的輸入必須為標準格式,並且P2SH腳本必須使用importaddress或addmultisigaddress在錢包中(以計算費用)。
您可以通過檢查listunspent輸出中的“solvable”字段來查看是否是這種情況。
當前,watch-only僅支持pay-to-pubkey,multisig及其P2SH版本
參數1 - hexstring
類型:字符串,必填
原始交易的十六進製字符串
參數2 - options
類型:json對象,可選
- 為了向後兼容:傳遞true而不是對象將導致{“includeWatching”:true}
“replaceable”:布爾值,(布爾值,可選,默認值=後退到錢包的默認值)將此交易標記為BIP125可替換。允許將此交易替換為費用較高的交易“conf_target”:n,(數字,可選,默認值=還原為錢包的默認值)確認目標(以塊為單位)“estimate_mode”:“str”,(字符串,可選,默認值= UNSET)費用估算模式,必須是以下之一:“UNSET” “ECONOMICAL” “CONSERVATIVE”}
{
"changeAddress": "str", (string, optional, default=pool address) The bitcoin address to receive the change
"changePosition": n, (numeric, optional, default=random) The index of the change output
"change_type": "str", (string, optional, default=set by -changetype) The output type to use. Only valid if changeAddress is not specified. Options are "legacy", "p2sh-segwit", and "bech32".
"includeWatching": bool, (boolean, optional, default=false) Also select inputs which are watch only
"lockUnspents": bool, (boolean, optional, default=false) Lock selected unspent outputs
"feeRate": amount, (numeric or string, optional, default=not set: makes wallet determine the fee) Set a specific fee rate in BTC/kB
"subtractFeeFromOutputs": [ (json array, optional, default=empty array) A json array of integers.
The fee will be equally deducted from the amount of each specified output.
Those recipients will receive less bitcoins than you enter in their corresponding amount field.
If no outputs are specified here, the sender pays the fee.
vout_index, (numeric) The zero-based output index, before a change output is added.
...
],
參數3 - iswitness
類型:布爾值,可選,默認值=取決於啟發式測試
- 交易十六進製是否為序列化見證交易
如果不存在見證,則將在解碼中使用啟發式測試
返回結果
{
"hex": "value", (string) The resulting raw transaction (hex-encoded string)
"fee": n, (numeric) Fee in BTC the resulting transaction pays
"changepos": n (numeric) The position of the added change output, or -1
}
示例
創建沒有輸入的交易:
bitcoin-cli createrawtransaction "[]" "{\"myaddress\":0.01}"
添加足夠的無符號輸入以滿足輸出值:
bitcoin-cli fundrawtransaction "rawtransactionhex"
簽署交易:
bitcoin-cli signrawtransactionwithwallet "fundedtransactionhex"
發送交易:
bitcoin-cli sendrawtransaction "signedtransactionhex"
相關用法
- Bitcoin analyzepsbt用法及代碼示例
- Bitcoin combinepsbt用法及代碼示例
- Bitcoin combinerawtransaction用法及代碼示例
- Bitcoin converttopsbt用法及代碼示例
- Bitcoin createpsbt用法及代碼示例
- Bitcoin createrawtransaction用法及代碼示例
- Bitcoin decodepsbt用法及代碼示例
- Bitcoin decoderawtransaction用法及代碼示例
- Bitcoin decodescript用法及代碼示例
- Bitcoin finalizepsbt用法及代碼示例
- Bitcoin getrawtransaction用法及代碼示例
- Bitcoin joinpsbts用法及代碼示例
- Bitcoin sendrawtransaction用法及代碼示例
- Bitcoin signrawtransactionwithkey用法及代碼示例
- Bitcoin testmempoolaccept用法及代碼示例
- Bitcoin utxoupdatepsbt用法及代碼示例
注:本文由純淨天空篩選整理自bitcoin.org大神的英文原創作品 Bitcoin fundrawtransaction。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。