比特币RPC API中文手册

区块链API
GetBestBlockHash/获取链头区块哈希 GetBlock/获取指定哈希的区块 GetBlockChainInfo/获取区块链当前状态 GetBlockCount/获取区块数量 GetBlockHash/获取指定高度区块的哈希 GetBlockHeader/获取指定哈希区块头 GetChainTips/获取全部链头区块 GetDifficulty/获取出块难度 GetMemPoolAncestors GetMemPoolDescendants GetMemPoolEntry GetMemPoolInfo/获取交易池信息 GetRawMemPool/获取交易池详情 GetTxOut/获取交易输出信息 GetTxOutProof/获取交易在区块中的证据 GetTxOutSetInfo/获取交易输出集信息 PreciousBlock PruneBlockChain VerifyChain/校验本地区块 VerifyTxOutProof
节点控制API
GetRpcInfo/获取rpc服务器信息 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/获取锁定状态UTXO ListReceivedByAccount ListReceivedByAddress/按地址统计收币数量 ListSinceBlock/查询指定区块后发生的钱包交易 ListTransactions/查询最近发生的钱包交易 ListUnspent/查询钱包UTXO LockUnspent/锁定或解锁指定的UTXO Move RemovePrunedFunds SendFrom SendMany SendToAddress/向指定地址发送比特币 SetAccount SetTxFee/设置交易手续费率 SignMessage/签名消息 SignMessageWithPrivKey/用指定私钥签名消息 WalletLock/锁定钱包 WalletPassphrase/解锁钱包 WalletPassphraseChange/修改钱包密码

GetBlockChainInfo/获取区块链当前状态

getblockchaininfo调用返回区块链的当前状态。

参数

返回值

getblockchaininfo调用返回一个描述区块链当前状态的对象,其结构如下:

  • chain:区块链名称,可以是:main、test或regtest
  • blocks:本地最优链中的已验证区块数量
  • headers:本地最有区块头链表中的已验证区块头数量
  • bestblockhash:本地最优链中最高区块的哈希
  • difficulty:区块难度
  • mediantime:最近区块之前的11个区块的中位时间
  • verificationprogress:区块验证进度,0.0~1.0
  • chainwork:
  • pruned:
  • pruneheight:
  • softforks:软分叉描述数组,成员结构如下:
    • id:
    • version:
    • enforce:
    • status:
    • found:
    • required:
    • window:
    • reject:
    • status:
  • bip9_softforks
    • name: 一个BIP39软分叉描述对象,结构如下
    • status:当前的状态,可以是以下值之一:
      - defined
        - started
        - locked_in
        - active
        - failed
      
    • bit:在软件版本字段中的位号
    • startTime:软分叉开始时间戳
    • timeout:超时时间戳
    • since:

示例代码

下面的命令返回区块链的总体信息:

~$ bitcoin-cli getblockchaininfo

输出结果如下:

{
  "chain": "main",
  "blocks": 464562,
  "headers": 464562,
  "bestblockhash": "00000000000000000085bd56990c579a36bade6ea427646612f13476edb30ceb",
  "difficulty": 521974519553.6282,
  "mediantime": 1493758169,
  "verificationprogress": 0.999989733170878,
  "chainwork": "00000000000000000000000000000000000000000052c26f32ffa22706efd28c",
  "pruned": false,
  "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": true
      }
    },
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": true
      }
    },
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": true
      }
    }
  ],
  "bip9_softforks": {
    "csv": {
      "status": "active",
      "startTime": 1462060800,
      "timeout": 1493596800,
      "since": 419328
    },
    "segwit": {
      "status": "started",
      "bit": 1,
      "startTime": 1479168000,
      "timeout": 1510704000,
      "since": 439488
    }
  }
}