Expand description
CKB RPC modules
This RPC document is generated by Rust Doc, so it will take some concept conversions to map from the Rust structures to the JSONRPC.
§JSONRPC Methods
The section Traits lists all the RPC modules. CKB allows enabling and disabling RPC
methods by modules. The default enabled ones are enabled modules are “Net”, “Pool”, “Miner”,
“Chain”, “Stats”, “Subscription”, “Experiment”. As you can see, the Rpc suffix is removed in
the config file.
The section Required methods lists all the RPC methods in the module. See module PoolRpc.
Use the RPC send_transaction in the module PoolRpc as an example.
fn send_transaction(
^^^^^^^^^^^^^^^^
`-- JSONRPC method name
&self,
^^^^^
`-- ignore this
,--------------------------------------------
| tx: Transaction,
| outputs_validator: Option<OutputsValidator>
`--------------------------------------------
`-- Request params list as pairs of "name: Type"
) -> Result<H256>;
^^^^
`-- Response Typesend_transaction- The JSONRPC method name.tx: Transaction- The first param in the request params list which name istxand type isTransaction. The type links to the JSON object definition of a CKB transaction.outputs_validator: Option<OutputsValidator>- The second param. TheOptionshows that this argument is optional. The document forOutputsValidatorshows thatoutputs_validatoris an enum type which possible values include “well_known_scripts_only” and “passthrough”.-> Result<H256>- The type inside theResultafter->is the response type. In this example, it isH256which is a 32-bytes binary encoded as a hex string.
The RPC errors are documented in RPCError.
§JSONRPC Deprecation Process
A CKB RPC method is deprecated in three steps.
First, the method is marked as deprecated in the CKB release notes and RPC document. However, the RPC method is still available. The RPC document will have the suggestion of alternative solutions.
The CKB dev team will disable any deprecated RPC methods starting from the next minor version
release. Users can enable the deprecated methods via the config file option rpc.enable_deprecated_rpc.
Once a deprecated method is disabled, the CKB dev team will remove it in a future minor version release.
For example, a method is marked as deprecated in 0.35.0, it can be disabled in 0.36.0 and removed in 0.37.0. The minor versions are released monthly, so there’s at least a two-month buffer for a deprecated RPC method.
§JSON Cheatsheet
CKB uses a framework to serialize into and deserialize from JSON. Some Rust std-lib structures will be used in requests and responses. The following cheatsheet shows how to map them into JSON values.
| Rust | JSON |
|---|---|
() | null |
bool | boolean |
String | string |
Option<T> | either null or T |
Vec<T> | array of T |
CKB RPC does not use JSON numbers because of the precision problem. Float point numbers are not
used in the RPC, and integers are encoded as 0x-prefixed hex string such as 0x10 for decimal
value 16.
The other types will have their own documentation pages. Unless the JSON format is explicitly described in the documentation page, the rust Struct is serialized as a JSON object, and Enum is serialized as a JSON string.
For example, OutPoint is a struct having the following fields
tx_hash: H256
index: Uint32An example OutPoint JSON looks like
{
"index": "0xffffffff",
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}Status is a Rust enum
pub enum Status {
Pending,
Proposed,
Committed,
}The enum values are represented as JSON strings in the lowercase, underscore-concatenated form. So, in
JSON, Status can be one of “pending”, “proposed” or “committed”.
Structs§
- Terminal
Cache - Terminal cache for storing expensive computations
Traits§
- Alert
Rpc - RPC Module Alert for network alerts.
- Chain
Rpc - RPC Module Chain for methods related to the canonical chain.
- Debug
Rpc - RPC Module Debug for internal RPC methods.
- Experiment
Rpc - RPC Module Experiment for experimenting methods.
- Indexer
Rpc - RPC Module Indexer.
- Integration
Test Rpc - RPC for Integration Test.
- Miner
Rpc - RPC Module Miner for miners.
- NetRpc
- RPC Module Net for P2P network.
- PoolRpc
- RPC Module Pool for transaction memory pool.
- Rich
Indexer Rpc - RPC Module Rich Indexer.
- Stats
Rpc - RPC Module Stats for getting various statistic data.
- Subscription
Rpc - RPC Module Subscription that CKB node will push new messages to subscribers, support with WebSocket or TCP.
- Terminal
Rpc - RPC Terminal Module, specifically designed for TUI (Terminal User Interface) applications.
Functions§
- add_
alert_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
chain_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
debug_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
experiment_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
indexer_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
integration_ test_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
miner_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
net_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
pool_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
rich_ indexer_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
stats_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
subscription_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - add_
terminal_ rpc_ methods - Add RPC methods to the given
jsonrpc_utils::jsonrpc_core::MetaIoHandler. - alert_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- chain_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- debug_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- experiment_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- indexer_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- integration_
test_ rpc_ doc - Generate OpenRPC document for the RPC methods.
- miner_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- net_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- pool_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- rich_
indexer_ rpc_ doc - Generate OpenRPC document for the RPC methods.
- stats_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- subscription_
rpc_ doc - Generate OpenRPC document for the RPC methods.
- terminal_
rpc_ doc - Generate OpenRPC document for the RPC methods.