当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Bitcoin fundrawtransaction用法及代码示例


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