JSON-RPC API
In order for a software application to interact with the Conflux blockchain - either by reading blockchain data or sending transactions to the network - it must connect to an Conflux node.
For this purpose, every Conflux client implements a JSON-RPC specification, so there are a uniform set of methods that applications can rely on regardless of the specific node or client implementation.
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. It defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments. It uses JSON (RFC 4627) as data format.
CONVENIENCE LIBRARIES
While you may choose to interact directly with Conflux clients via the JSON-RPC API, there are often easier options for dapp developers. Many JavaScript and backend API libraries exist to provide wrappers on top of the JSON-RPC API. With these libraries, developers can write intuitive, one-line methods in the programming language of their choice to initialize JSON-RPC requests (under the hood) that interact with Conflux.
JSON-RPC endpoints
Currently, Conflux has a Rust implementation that supports JSON-RPC 2.0 over an HTTP, TPC, or WebSocket connection.
If you are a node operator, you can enable and configure various RPC interfaces through the TOML config file, or directly by passing command line arguments. The main configuration items are listed in the table below. Note that if you want to enable HTTPS or access control, you will need to set up a proxy for your node.
config parameter | cli parameter | default port | enabled by default |
---|---|---|---|
jsonrpc_ws_port | --jsonrpc-ws-port | 12535 | no |
jsonrpc_tcp_port | --jsonrpc-tcp-port | 12536 | no |
jsonrpc_http_port | --jsonrpc-http-port | 12537 | no |
jsonrpc_local_tcp_port | - | 12538 | no |
jsonrpc_local_http_port | - | 12539 | yes |
Method Namespace
The JSON-RPC API is organized into namespaces, with each namespace containing a set of methods. All methods name in one namespace have a same prefix, for example all methods in cfx namespace
have a same prefix cfx_
eg cfx_getBalance
, cfx_getTransactionByHash
. The following namespaces are currently supported:
📄️ cfx 命名空间
The core JSON-RPC API of Conflux.
📄️ txpool 命名空间
txpool 相关的 RPC 可以让开发者获取更多关于交易池的信息。 Which was introduced from conflux-rust v1.1.6.
📄️ pos 命名空间
The `pos` namespace includes RPCs related to PoS consensus.
📄️ debug Namespace
A set of methods related to debugging
📄️ trace 命名空间
Through trace RPCs we can know the transaction executive details. To use these RPC Conflux archive node need set two additional config:
📄️ 发布/订阅 API
The Publish-Subscribe API of Conflux Core Space
📄️ 常见 RPC 错误
常见错误
🗃️ RPC Behaviour
2 个项目