Skip to main content

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 parametercli parameterdefault portenabled by default
jsonrpc_ws_port--jsonrpc-ws-port12535no
jsonrpc_tcp_port--jsonrpc-tcp-port12536no
jsonrpc_http_port--jsonrpc-http-port12537no
jsonrpc_local_tcp_port-12538no
jsonrpc_local_http_port-12539yes

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: