Enable the Subscription RPC module and set a loopback WebSocket address in the existing [rpc] section of kryvon.toml, then restart Kryvon.
ws_listen_address = "127.0.0.1:28114"
Set tcp_listen_address = "127.0.0.1:18114" in the same section for JSON-RPC subscriptions over TCP.
Subscribe
Call subscribe on an open connection with one topic name. The response returns an opaque subscription ID.
| Topic | Payload in params.result |
|---|---|
new_tip_header |
Canonical block header |
new_tip_block |
Canonical block |
new_transaction |
Transaction accepted into the mempool |
proposed_transaction |
Proposed mempool transaction |
rejected_transaction |
Transaction entry and rejection reason |
logs |
Node log record |
The node sends notifications with method: "subscribe". Match params.subscription to the returned ID and parse the JSON string in params.result.
Unsubscribe
Send unsubscribe with the ID the node returned on the same connection. This example subscribes and immediately unsubscribes to confirm both requests. Run it with Node.js 22 or later.
const socket = new WebSocket('ws://127.0.0.1:28114');
const send = (id, method, params) => socket.send(JSON.stringify({
jsonrpc: '2.0', id, method, params,
}));
socket.addEventListener('open', () => send(1, 'subscribe', ['new_tip_header']));
socket.addEventListener('message', ({ data }) => {
const reply = JSON.parse(data);
if (reply.error) {
console.error(reply.error.message);
socket.close();
} else if (reply.id === 1) {
console.log('Subscription:', reply.result);
send(2, 'unsubscribe', [reply.result]);
} else if (reply.id === 2) {
console.log('Unsubscribed:', reply.result);
socket.close();
}
});