比特币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

ListUnspent

The listunspent RPC returns an array of unspent transaction outputs belonging to this wallet. Note: as of Bitcoin Core 0.10.0, outputs affecting watch-only addresses will be returned; see the spendable field in the results described below.

参数

  • MinimumConfirmations:交易最少确认数,默认值:1
  • MaximumConfirmations:交易最多确认数,默认值:9999999
  • Addresses:交易输出中应当包含的地址数组

返回值

listunspent调用返回UTXO描述数组,成员结构如下:

  • txid:交易id
  • vout:输出序号
  • address:地址
  • account:关联账户
  • scriptPubKey:公钥脚本
  • redeemScript:赎回脚本
  • amount:金额
  • confirmations:确认数
  • spendable:是否可消费,当钱包中包含对应的私钥时,该值为true
  • solvable:是否可用,钱包中包含私钥时该值被忽略

示例代码

下面的命令返回节点钱包中包含6~9999999个确认并且支付到指定地址的UTXO:

~$ bitcoin-cli -testnet listunspent 6 99999999 '''
  [
    "mgnucj8nYqdrPFh2JfZSB1NmUThUGnmsqe"
  ]
'''

输出结果如下:

[
    {
        "txid" : "d54994ece1d11b19785c7248868696250ab195605b469632b7bd68130e880c9a",
        "vout" : 1,
        "address" : "mgnucj8nYqdrPFh2JfZSB1NmUThUGnmsqe",
        "account" : "test label",
        "scriptPubKey" : "76a9140dfc8bafc8419853b34d5e072ad37d1a5159f58488ac",
        "amount" : 0.00010000,
        "confirmations" : 6210,
        "spendable" : true,
        "solvable" : true
    }
]