WebSocket guide

WebSocket Authentication

Send the API key during the WebSocket upgrade without exposing secrets.

The NoLimitNodes WebSocket endpoint reads x-api-key from the opening HTTP upgrade request.

Node.js

The ws package supports custom headers.

npm install ws
import WebSocket from "ws" const socket = new WebSocket("wss://ws.nln.clr3.org", {  headers: {    "x-api-key": process.env.NLN_API_KEY,  },}) socket.on("open", () => {  socket.send(JSON.stringify({    jsonrpc: "2.0",    id: "logs",    method: "logsSubscribe",    params: ["all", { commitment: "confirmed" }],  }))}) socket.on("message", (data) => {  console.log(JSON.parse(data.toString()))})

Browser apps

The browser WebSocket API does not accept custom headers.

Use a backend relay:

  1. Your browser opens an authenticated connection to your backend.
  2. Your backend opens the NoLimitNodes connection with x-api-key.
  3. Your backend forwards only the events needed by the signed-in user.

Keep these controls on the relay:

  • User authentication
  • Per-user subscription limits
  • Allowed method list
  • Allowed account and program list
  • Message size limits
  • Idle connection cleanup

Terminal tools

wscat \  -c wss://ws.nln.clr3.org \  -H "x-api-key: YOUR_API_KEY"