CometBFT 提供了全面的 RPC API,用于与节点交互、查询区块链数据、广播交易以及订阅实时事件。

RPC API 参考

访问 API 参考页面,查看所有 CometBFT RPC 方法的完整列表
RPC 服务器支持多种协议:
  • 通过 HTTP 的 URI - 类似 REST 的接口,适合简单查询
  • 通过 HTTP 的 JSONRPC - 标准的 JSON-RPC 2.0 协议
  • 通过 WebSockets 的 JSONRPC - 支持订阅的持久连接

快速开始

默认情况下,RPC 服务器监听 tcp://127.0.0.1:26657。你可以使用 curl 进行查询:
# Get node status
curl http://localhost:26657/status

# Get block at height 5
curl http://localhost:26657/block?height=5

# Health check
curl http://localhost:26657/health

配置

可以在 config.toml 文件的 [rpc] 部分中配置 RPC 服务器:
[rpc]

# TCP or UNIX socket address for the RPC server to listen on
laddr = "tcp://127.0.0.1:26657"

# A list of origins a cross-domain request can be executed from
cors_allowed_origins = []

# Maximum number of simultaneous connections
max_open_connections = 900
有关 RPC 配置选项的更多细节,请参阅配置页面。
CometBFT provides a comprehensive RPC API for interacting with nodes, querying blockchain data, broadcasting transactions, and subscribing to real-time events.

RPC API Reference

Visit the API Reference page for a list of all CometBFT RPC methods
The RPC server supports multiple protocols:
  • URI over HTTP - REST-like interface for simple queries
  • JSONRPC over HTTP - Standard JSON-RPC 2.0 protocol
  • JSONRPC over WebSockets - Persistent connection with subscription support

Quick Start

By default, the RPC server listens on tcp://127.0.0.1:26657. You can query it using curl:
# Get node status
curl http://localhost:26657/status

# Get block at height 5
curl http://localhost:26657/block?height=5

# Health check
curl http://localhost:26657/health

Configuration

The RPC server can be configured in your config.toml file under the [rpc] section:
[rpc]

# TCP or UNIX socket address for the RPC server to listen on
laddr = "tcp://127.0.0.1:26657"

# A list of origins a cross-domain request can be executed from
cors_allowed_origins = []

# Maximum number of simultaneous connections
max_open_connections = 900
See the Configuration page for more details on RPC configuration options.