rpckit
A modular TypeScript library for JSON-RPC communication with type-safe transports, automatic batching, and built-in failover.
version1.0.0
typed100%
licenseMIT
Modular
Pick only the transports you need - WebSocket, TCP, HTTP, or all three
Type-Safe
Full TypeScript support with schema-based typing for RPC methods
Resilient
Built-in failover with fallback and m-of-n quorum cluster transports
Efficient
Automatic request batching, connection pooling, and keep-alive
Overview
import { webSocket } from '@rpckit/websocket/electrum-cash'
// Create a transport with protocol-specific defaults
const transport = webSocket('wss://electrum.example.com:50004')
// Make requests (handshake sent automatically)
const tip = await transport.request('blockchain.headers.get_tip')
// Subscribe to updates
const unsubscribe = await transport.subscribe(
'blockchain.headers.subscribe',
(header) => console.log('New block:', header)
)
// Clean up
await unsubscribe()
await transport.close()Features
- Multiple Transports - WebSocket, TCP (with TLS), and HTTP support
- Meta-Transports - Fallback for failover, Cluster for m-of-n quorum consensus
- Automatic Batching - Combines multiple requests into single JSON-RPC batch calls
- Subscriptions - First-class subscription support with automatic resubscription on reconnect
- Type Safety - Define schemas for compile-time checking of method names and parameters
- Connection Management - Keep-alive, reconnection with exponential backoff, connection pooling
- URL Parsing - Create transports from URL strings with
parse('wss://...')
Packages
| Package | Description |
|---|---|
@rpckit/core | Core types, BatchScheduler, parse(), withRetry() |
@rpckit/websocket | WebSocket transport with subscriptions and reconnection |
@rpckit/tcp | TCP transport with TLS support (Node.js) |
@rpckit/http | HTTP transport for stateless requests |
@rpckit/fallback | Meta-transport for failover across multiple transports |
@rpckit/cluster | Meta-transport for m-of-n quorum consensus |