Skip to main content

JSON-RPC API

KalyChain provides a JSON-RPC 2.0 API for blockchain interactions over HTTP, WebSocket, and IPC.

Overview

JSON-RPC is the primary interface for:

  • Querying blockchain state
  • Submitting transactions
  • Managing node administration
  • Accessing consensus information

Transport Options

HTTP

Most common for single requests:

curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://localhost:8545

Enable with: --rpc-http-enabled

WebSocket

Better for subscriptions and persistent connections:

const ws = new WebSocket('ws://localhost:8546');
ws.send(JSON.stringify({
jsonrpc: "2.0",
method: "eth_blockNumber",
params: [],
id: 1
}));

Enable with: --rpc-ws-enabled

IPC

For local communication (lowest latency, highest security):

Enable with: --Xrpc-ipc-enabled

Default socket path: <data-path>/kaly.ipc

Request Format

{
"jsonrpc": "2.0",
"method": "method_name",
"params": [],
"id": 1
}
FieldDescription
jsonrpcAlways "2.0"
methodAPI method name
paramsMethod parameters (array or object)
idRequest identifier (returned in response)

Response Format

Success

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x10"
}

Error

{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "Invalid params"
}
}

Common Methods

Block Queries

MethodDescription
eth_blockNumberCurrent block number
eth_getBlockByNumberBlock by number
eth_getBlockByHashBlock by hash

Account Queries

MethodDescription
eth_getBalanceAccount balance
eth_getTransactionCountAccount nonce
eth_getCodeContract code

Transaction Operations

MethodDescription
eth_sendRawTransactionSubmit signed transaction
eth_getTransactionByHashTransaction by hash
eth_getTransactionReceiptTransaction receipt

QBFT Methods

MethodDescription
qbft_getValidatorsByBlockNumberValidators at block
qbft_proposeValidatorVoteVote on validator
qbft_getPendingVotesPending votes
qbft_getSignerMetricsValidator metrics

Block Parameters

Many methods accept a block parameter:

ValueDescription
"latest"Most recent block
"earliest"Genesis block
"pending"Pending state
"finalized"Latest finalized block
"safe"Latest safe block
"0x..."Specific block number (hex)

Example:

curl -X POST --data '{
"jsonrpc":"2.0",
"method":"eth_getBalance",
"params":["0xAddress", "latest"],
"id":1
}' http://localhost:8545

Readiness and Liveness

Check node health:

Liveness

curl http://localhost:8545/liveness

Returns 200 OK if the node is running.

Readiness

curl http://localhost:8545/readiness

Returns 200 OK if the node is synced and ready to accept requests.

API Methods Enabled by Default

Not all methods are enabled by default. Use --rpc-http-api and --rpc-ws-api to specify:

kaly --rpc-http-enabled \
--rpc-http-api=ETH,NET,WEB3,QBFT

Available APIs

APIDescription
ETHEthereum methods
NETNetwork methods
WEB3Utility methods
ADMINNode administration
DEBUGDebugging methods
TXPOOLTransaction pool
QBFTQBFT consensus

Batch Requests

Send multiple requests in one HTTP call:

curl -X POST --data '[
{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1},
{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":2}
]' http://localhost:8545

Response:

[
{"jsonrpc":"2.0","id":1,"result":"0x100"},
{"jsonrpc":"2.0","id":2,"result":"0xf30"}
]

Using Geth Console

Connect using Geth's JavaScript console:

geth attach http://localhost:8545

Then use JavaScript:

> eth.blockNumber
256
> eth.getBalance("0xAddress")
"1000000000000000000"

Error Codes

CodeMeaning
-32700Parse error
-32600Invalid request
-32601Method not found
-32602Invalid params
-32603Internal error

Further Reading