RPC 服务器提供了一个用于与 CometBFT 节点交互的 API,包括区块链数据、交易广播和节点信息。The RPC server provides an API for interacting with a CometBFT node, including blockchain data, transaction broadcasting, and node information.
[rpc]# TCP or UNIX socket address for the RPC server to listen onladdr = "tcp://127.0.0.1:26657"# A list of origins a cross-domain request can be executed from# Default value '[]' disables cors support# Use '["*"]' to allow any origincors_allowed_origins = []# A list of methods the client is allowed to use with cross-domain requestscors_allowed_methods = ["HEAD", "GET", "POST"]# A list of non simple headers the client is allowed to use with cross-domain requestscors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"]
# Get block at height 5curl http://localhost:26657/block?height=5# Get node statuscurl http://localhost:26657/status# Get validators at height 1curl http://localhost:26657/validators?height=1
# Get the latest blockcurl http://localhost:26657/block# Get block at specific heightcurl http://localhost:26657/block?height=100# Search for transactionscurl 'http://localhost:26657/tx_search?query="tx.height>100"&prove=false'
在侧边栏中浏览完整的 API 参考文档,包含约 30 个 RPC 方法,以及可交互示例和详细参数说明
WebSocket Subscriptions
进一步了解如何订阅实时事件
CometBFT RPC is a remote procedure call protocol that provides access to blockchain data, transaction broadcasting, validator information, and node status. The RPC server supports multiple transport protocols to accommodate different use cases.CometBFT supports the following RPC 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
The default RPC listen address is tcp://127.0.0.1:26657. To set another address, update the laddr config parameter:
[rpc]# TCP or UNIX socket address for the RPC server to listen onladdr = "tcp://127.0.0.1:26657"# A list of origins a cross-domain request can be executed from# Default value '[]' disables cors support# Use '["*"]' to allow any origincors_allowed_origins = []# A list of methods the client is allowed to use with cross-domain requestscors_allowed_methods = ["HEAD", "GET", "POST"]# A list of non simple headers the client is allowed to use with cross-domain requestscors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"]
# Get block at height 5curl http://localhost:26657/block?height=5# Get node statuscurl http://localhost:26657/status# Get validators at height 1curl http://localhost:26657/validators?height=1
Unsafe Methods: Methods in the “Unsafe” category can affect node operation and must be manually enabled in the configuration. They should only be used by node operators who understand the implications.
# Get the latest blockcurl http://localhost:26657/block# Get block at specific heightcurl http://localhost:26657/block?height=100# Search for transactionscurl 'http://localhost:26657/tx_search?query="tx.height>100"&prove=false'