跳到主要内容

JSON-RPC API

为了使一个软件应用程序与 Conflux 区块链交互——无论是读取区块链数据还是向网络发送交易——它必须连接到一个 Conflux 节点。

为此,每个Conflux客户端都执行了一个JSON-RPC 规范,因此无论特定节点和客户端执行,应用程序都可以依赖一组统一的方法。

JSON-RPC 是一个无状态、轻量级的远程程序调用(RPC)协议。 它定义了几个数据结构以及它们处理的规则。 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. 它使用 JSON (RFC 4627) 作为数据格式。

CONVENIENCE LIBRARIES

虽然你可以选择通过JSON-RPC API直接与Conflux客户端交互,但对于dapp开发者来说,通常有更方便的选择。 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 端点

Currently, Conflux has a Rust implementation that supports JSON-RPC 2.0 over an HTTP, TPC, or WebSocket connection.

如果你是一个节点搭设者,你可以通过 TOML 配置文件,或者直接传递命令行参数,来启用和配置各种 RPC 接口。 主要的配置项如下表所示。 Note that if you want to enable HTTPS or access control, you will need to set up a proxy for your node.

配置参数命令行参数默认端口:默认启用
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

方法命名空间

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. 当前支持下列命名空间: