JSON-RPC server for querying Typeberry node data.
Implements the JIP-2 specification.
The RPC server provides a JSON-RPC 2.0 interface over WebSocket for querying blockchain data. It runs in-process with the JAM node, sharing the database handle (fjall) and is configured via the node's config file.
Add an rpc section to the node config JSON to enable the RPC server:
{
"rpc": {
"port": 19800
}
}
Omit the rpc key to disable the RPC server.
In dev mode (jam dev <index>), the port is shifted by the validator index (e.g. jam dev 1 listens on 19801, jam dev 2 on 19802).
The following JSON-RPC methods are available according to the JIP-2 specification:
bestBlock - Returns the hash of the best blockfinalizedBlock - Returns the hash of the finalized block (currently returns best block)listServices - Lists all registered servicesparent - Returns the parent block hash for a given blockserviceData - Retrieves service account dataservicePreimage - Retrieves a preimage for a given hashserviceRequest - Retrieves service request dataserviceValue - Retrieves service value by keystateRoot - Returns the state root hashstatistics - Returns blockchain statisticsbeefyRoot - Returns the BEEFY root (awaits Chapter 12)parameters - Returns chain parameterssubmitPreimage - Submits a preimagesubmitWorkPackage - Submits a work packageimport WebSocket from 'ws';
const ws = new WebSocket('ws://localhost:19800');
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'bestBlock',
params: []
}));
});
ws.on('message', (data) => {
const response = JSON.parse(data);
console.log('Best block:', response.result);
});
echo '{"jsonrpc":"2.0","id":1,"method":"bestBlock","params":[]}' | websocat ws://localhost:19800
The server returns standard JSON-RPC 2.0 error responses:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32601,
"message": "Method not found"
}
}
Common error codes:
-32700 - Parse error-32600 - Invalid request-32601 - Method not found-32602 - Invalid params-32603 - Internal error