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 Namespace
The core JSON-RPC API of Conflux.
📄️ txpool Namespace
txpool related RPCs which can enable developer get more info about transaction pool. Which was introduced from conflux-rust v1.1.6.
📄️ pos Namespace
The `pos` namespace includes RPCs related to PoS consensus.
📄️ debug Namespace
A set of methods related to debugging
📄️ trace Namespace
Through trace RPCs we can know the transaction executive details. To use these RPC Conflux archive node need set two additional config:
📄️ Publish-Subscribe API
The Publish-Subscribe API of Conflux Core Space
📄️ Common RPC errors
Common errors
🗃️ RPC Behaviour
2 items