JSON RPC
How to access the KalyChain API using JSON-RPC
Last updated
How to access the KalyChain API using JSON-RPC
Last updated
JSON-RPC APIs allow you to interact with your node. JSON-RPC endpoints are not enabled by default.
!!! caution
To enable JSON-RPC over HTTP or WebSocket, use the and options.
To enable JSON-RPC over an , use the --Xrpc-ipc-enabled
option.
The geth console is a REPL (Read, Evaluate, & Print Loop) JavaScript console. Use JSON-RPC APIs supported by geth and KalyChain directly in the console.
To use the geth console with Kaly:
Start Kaly with the or --Xrpc-ipc-enabled
option.
Specify which APIs to enable using the or --Xrpc-ipc-api
option.
Start the geth console specifying the JSON-RPC endpoint:
!!! example
!!! example
!!! example
You can use curl
to make multiple RPC requests over HTTP at the same time. Send the requests as an array, and receive an array of responses.
!!! example
First connect to the WebSocket server using wscat
(you only need to connect once per session):
After you establish a connection, the terminal displays a '>' prompt. Send individual requests as a JSON data package at each prompt.
!!! Example
You can use wscat
to make multiple RPC requests over WebSocket at the same time. Send the requests as an array, and receive an array of responses.
!!! example
!!! note
Kaly provides readiness and liveness endpoints to confirm the Kaly node status. Both return a 200 OK
status when ready or live and a 503 Service Unavailable
status if not ready or live.
Use the query parameters minPeers
and maxBlocksBehind
to adjust the number of peers required and the number of blocks tolerance.
=== "Readiness endpoint"
=== "curl request example"
=== "Query parameters example"
The liveness check requires the JSON-RPC server to be up. You can use the endpoint to verify that the node can respond to RPC calls. The status in the response will always be UP
.
=== "Liveness endpoint"
=== "curl request example"
Kaly enables the ETH
, NET
, and WEB3
API methods by default.
!!! caution
The block parameter can have the following values:
blockNumber
: quantity
- The block number, specified in hexadecimal or decimal. 0 represents the genesis block.
earliest
: tag
- The earliest (genesis) block.
latest
: tag
- The last block mined.
finalized
: tag
- The most recent crypto-economically secure block. It cannot be reorganized outside manual intervention driven by community coordination.
safe
: tag
- The most recent block that is safe from reorganization under honest majority and certain synchronicity assumptions.
Use the geth console to call that geth and Kaly share.
Kaly disables by default.
To make RPC requests over HTTP, you can use .
To make RPC requests over WebSocket, you can use , a Node.js based command-line tool.
By default, the readiness check requires a connected peer and the node to be within two blocks of the best known block. If you have , you do not need peers. A live node with P2P disabled is always ready.
To enable the ADMIN
, CLIQUE
, DEBUG
, EEA
, IBFT
, MINER
, PERM
, PLUGINS
, PRIV
, TRACE
, and TXPOOL
API methods, use the , , or --Xrpc-ipc-api
options.
When you make requests that might have different results depending on the block accessed, the block parameter specifies the block. Methods such as have a block parameter.
pending
: tag
- The last block mined plus pending transactions. Use only with .