ws:// or wss:// URL to connect over WebSocket. This gives you a persistent connection and is the only transport that supports real-time event subscriptions.
Using High-Level Clients
Subscriptions
WebSocket connections can subscribe to new blocks and transactions:Reconnection
WebsocketClient reconnects automatically with exponential backoff (100 ms initial, doubling up to 5 seconds). Requests made while disconnected are queued and sent when the connection is restored.
Error Handler
TheWebsocketClient constructor accepts an optional error handler as its second argument:
Checking Subscription Support
Not all transports support event subscriptions. OnlyWebsocketClient implements the streaming interface. If you have a CometClient and need to check at runtime, verify the underlying RPC client is a WebsocketClient:
subscribeNewBlock(), subscribeNewBlockHeader(), or subscribeTx() on a CometBFT client backed by an HTTP transport throws "This RPC client type cannot subscribe to events".
Next Steps
HTTP Transport
Use HTTP for stateless request-response queries.
Timeouts
Configure WebSocket connection and broadcast timeouts.
Connection Errors
Handle WebSocket errors and reconnection failures.