WebSocket

Use WebSocket subscriptions for account changes, logs, signatures, slots, blocks, and votes.

Connect from a terminal

Install wscat, then pass your API key during the HTTP upgrade.

bash
npm install --global wscat
export NODE_API_KEY="YOUR_API_KEY"
wscat -c wss://ws.sol.cubestech.online -H "x-api-key: $NODE_API_KEY"

Send a slot subscription after the connection opens.

json
{
  "jsonrpc": "2.0",
  "id": "slots",
  "method": "slotSubscribe"
}

The first response contains a numeric subscription ID. Later messages use slotNotification.

json
{
  "jsonrpc": "2.0",
  "method": "slotNotification",
  "params": {
    "result": {
      "parent": 357954000,
      "root": 357953968,
      "slot": 357954001
    },
    "subscription": 42
  }
}

Stop the subscription

Pass the subscription ID to slotUnsubscribe.

json
{
  "jsonrpc": "2.0",
  "id": "stop-slots",
  "method": "slotUnsubscribe",
  "params": [42]
}

Browser clients

The browser WebSocket constructor has no option for custom upgrade headers. Do not place your API key in browser code.

Use one of these paths:

  • Open the connection from your backend.
  • Relay selected events to your browser.
  • Keep the cubestech key in server-side secrets.