Skip to main content
The WebSocket server provides a real-time streaming interface for Injective chain events. It wraps the gRPC Chain Stream server, allowing you to subscribe to blockchain updates using standard WebSocket connections instead of gRPC streams.

Prerequisites

  • A running Injective node with the Chain Stream gRPC server enabled
  • The [injective-websocket] section configured in your node’s app.toml

Configuration

Configure the WebSocket server in your node’s app.toml under the [injective-websocket] section.

Example configuration

app.toml
The WebSocket server requires the Chain Stream server to be enabled. Ensure the following is also configured in your app.toml:

Connecting to the server

Connect to the WebSocket endpoint at:
example.js

Subscribing to events

Send a JSON-RPC 2.0 request with the subscribe method. Each request must include:
  • jsonrpc — Always "2.0"
  • id — A positive integer used to identify responses for this subscription
  • method"subscribe"
  • params.req.subscription_id — A client-provided unique identifier for this subscription
  • params.req.filter — An object containing your subscription filters
A successful subscription returns:
After subscribing, you will receive stream updates with the same id.

Unsubscribing from events

Send a request with the unsubscribe method and the subscription_id you used when subscribing:
A successful unsubscribe returns:
The subscription_id must match exactly the ID you provided when creating the subscription.

Available filters

You can subscribe to any combination of the following event types. At least one filter must be specified. Use "*" as a wildcard to match all values for a parameter.

Response format

Stream responses follow the JSON-RPC 2.0 format. Each response contains updates for a single block. Only fields matching your subscription filters contain data.

Security considerations

The WebSocket server has certain security limitations to be aware of when deploying to production.
The server accepts connections from any origin. Deploy behind a reverse proxy that validates the Origin header to mitigate Cross-Site WebSocket Hijacking.
The server only supports unencrypted ws:// connections. Use a TLS-terminating reverse proxy to provide wss:// connections.
The server does not implement authentication. Use a reverse proxy with authentication middleware, API key validation, or network-level access controls (firewalls, VPNs).
While max-open-connections limits total connections, there is no per-client rate limiting. Implement rate limiting at the proxy level:

Operational notes

  • When a connection closes, all associated subscriptions are automatically cancelled
  • The server sends ping frames periodically to detect stale connections
  • The subscription_id must be unique within your connection — different connections can reuse the same IDs
  • Implement reconnection logic with exponential backoff on the client side
  • Use specific filters rather than wildcards (*) when possible to reduce data volume
  • Always set max-open-connections to a reasonable limit in production
Last modified on March 30, 2026