比特币RPC API中文手册

区块链API
GetBestBlockHash GetBlock GetBlockChainInfo GetBlockCount GetBlockHash GetBlockHeader GetChainTips GetDifficulty GetMemPoolAncestors GetMemPoolDescendants GetMemPoolEntry GetMemPoolInfo GetRawMemPool GetTxOut GetTxOutProof GetTxOutSetInfo PreciousBlock PruneBlockChain VerifyChain VerifyTxOutProof
节点控制API
GetInfo Help Stop
区块构造与挖矿API
Generate GenerateToAddress GetBlockTemplate GetMiningInfo GetNetworkHashPS PrioritiseTransaction SubmitBlock
P2P网络通信API
AddNode ClearBanned DisconnectNode GetAddedNodeInfo GetConnectionCount GetNetTotals GetNetworkInfo GetPeerInfo ListBanned Ping SetBan SetNetworkActive
裸交易相关API
CreateRawTransaction FundRawTransaction DecodeRawTransaction DecodeScript GetRawTransaction SendRawTransaction SignRawTransaction
工具类
CreateMultiSig EstimateFee EstimatePriority GetMemoryInfo ValidateAddress VerifyMessage
钱包相关
AbandonTransaction AddWitnessAddress AddMultiSigAddress BackupWallet BumpFee DumpPrivKey DumpWallet EncryptWallet GetAccountAddress GetAccount GetAddressesByAccount GetBalance GetNewAddress GetRawChangeAddress GetReceivedByAccount GetReceivedByAddress GetTransaction GetUnconfirmedBalance GetWalletInfo ImportAddress ImportMulti ImportPrunedFunds ImportPrivKey ImportWallet KeyPoolRefill ListAccounts ListAddressGroupings ListLockUnspent ListReceivedByAccount ListReceivedByAddress ListSinceBlock ListTransactions ListUnspent LockUnspent Move RemovePrunedFunds SendFrom SendMany SendToAddress SetAccount SetTxFee SignMessage SignMessageWithPrivKey WalletLock WalletPassphrase WalletPassphraseChange

FundRawTransaction

fundrawtransaction调用为交易增加输入,直到该交易的输入可以满足输出值 的要求。该调用不会修改已有的输入,同时会增加一个找零输出。

需要指出的是,如果交易之前的输入已经签名,那么在本调用完成后可能 需要重新签名。新增加的交易输入是未签名的,因此需要使用signrawtransaction 调用进行签名。所有的交易输入所引用的UTXO必须属于钱包内的交易。

参数

  • Hexstring:要添加输入的裸交易字符串
  • Options:额外的可选项,结构如下:
    • changeAddress:找零地址,如果不设置则自动从地址池中选择一个新地址
      • changePosition:找零输出的序号,如果不设置则随机选择在交易输出中的序号
      • includeWatching:是否使用watch-only地址的UTXO,默认值:false
      • lockUnspents:是否在调用执行后锁定UTXO,默认值:false
      • reserveChangeKey:是否预留找零密钥,默认值:true
      • feeRate:交易费率,如果不设置则由钱包决定
      • subtractFeeFromOutputs:交易费扣除数组

返回值

fundrawtransaction调用返回更新后的交易信息,结构如下:

  • hex:更新后的未签名交易字符串
  • fee:交易支付的手续费,单位:bitcoin
  • changepos:找零在交易输出中的序号

示例代码

下面的命令更新指定的裸交易:

~$ bitcoin-cli -testnet fundrawtransaction 01000000011da9283b4ddf8d\
89eb996988b89ead56cecdc44041ab38bf787f1206cd90b51e0000000000ffff\
ffff01405dc600000000001976a9140dfc8bafc8419853b34d5e072ad37d1a51\
59f58488ac00000000 
'{
    "changeAddress": "15gJiApWFGTN2iTteQwQbqasdT6dwGWwv6",
    "changePosition" : 1,
    "includeWatching" : false,
    "lockUnspents" : true,
    "feeRate" : 0.0001
}'

输出结果如下:

{
    "hex": "01000000011da9283b4ddf8d89eb996988b89ead56cecdc44041ab38bf787f1206cd90b51e0000000000ffffffff01405dc600000000001976a9140dfc8bafc8419853b34d5e072ad37d1a5159f58488ac00000000",
    "fee": 0.0000245,
    "changepos": 2
}