## WebSocket

*JSON-RPC subscriptions over WSS*

Open one socket and subscribe to slots, accounts, logs or programs. Each xSubscribe returns an integer id; the matching xUnsubscribe cancels it and frees its slot under the per-connection cap. Your [plan](https://carbium.sh/docs/limits.md) caps connections and subscriptions per account; Free carries 5 sockets.

```
# WebSocket
wscat -c 'wss://services.carbium.sh/?api-key=<YOUR_KEY>'
> {"jsonrpc":"2.0","id":1,"method":"slotSubscribe"}
< {"jsonrpc":"2.0","result":2282,"id":1}
< {"jsonrpc":"2.0","method":"slotNotification","params":{
   "subscription":2282,
   "result":{"slot":445686763,"parent":445686762,"root":445686730}}}
# header form: x-api-key: <YOUR_KEY>
```

### channels

| subscribe | notification | payload |
|---|---|---|
| accountSubscribe | accountNotification | account state on change, for streamed accounts; plain SOL wallets send nothing: use logsSubscribe mentions plus getBalance |
| programSubscribe | programNotification | account changes under a covered program; others answer -32010 |
| logsSubscribe | logsNotification | transaction logs, all or by mention |
| signatureSubscribe | signatureNotification | one confirmation, then it ends |
| slotSubscribe | slotNotification | each new processed slot |
| rootSubscribe | rootNotification | each new root |
| slotsUpdatesSubscribe | slotsUpdatesNotification | slot lifecycle updates |
| blockSubscribe | blockNotification | each new block, all or by mention; send maxSupportedTransactionVersion: 1 |
| voteSubscribe | refused (-32601) | Alpenglow takes vote transactions out of blocks |

### methods

#### slotSubscribe

5 + 20 a MiB sent

```
{"jsonrpc":"2.0","id":1,"method":"slotSubscribe","params":[]}
```

**answer**: subscription id, then notifications

#### slotsUpdatesSubscribe

25 + 20 a MiB sent

```
{"jsonrpc":"2.0","id":1,"method":"slotsUpdatesSubscribe","params":[]}
```

**answer**: subscription id, then notifications

#### rootSubscribe

5 + 20 a MiB sent

```
{"jsonrpc":"2.0","id":1,"method":"rootSubscribe","params":[]}
```

**answer**: subscription id, then notifications

#### accountSubscribe

25 + 20 a MiB sent

| param | type |   |   |
|---|---|---|---|
| address | pubkey | req |  |
| config | {encoding?, commitment?} | opt |  |

```
{"jsonrpc":"2.0","id":1,"method":"accountSubscribe","params":["SysvarC1ock11111111111111111111111111111111",{"encoding":"base64","commitment":"finalized"}]}
```

**answer**: subscription id, then notifications

#### programSubscribe

200 + 20 a MiB sent

| param | type |   |   |
|---|---|---|---|
| program | pubkey | req | must be in the covered set |
| config | {encoding?} | opt |  |

```
{"jsonrpc":"2.0","id":1,"method":"programSubscribe","params":["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",{"encoding":"base64"}]}
```

**answer**: subscription id, then notifications

**refuses**: 403 -32010 program outside the covered set

#### logsSubscribe

200 for all, 25 with mentions; + 20 a MiB sent

| param | type |   |   |
|---|---|---|---|
| filter | "all" \| {mentions: [pubkey]} | req | mentions costs 25, all costs 200 |

```
{"jsonrpc":"2.0","id":1,"method":"logsSubscribe","params":["all"]}
```

**answer**: subscription id, then notifications

#### signatureSubscribe

5 + 20 a MiB sent

| param | type |   |   |
|---|---|---|---|
| signature | string | req |  |
| config | {commitment?} | opt |  |

```
{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["<signature>",{"commitment":"finalized"}]}
```

**answer**: subscription id, then notifications

#### blockSubscribe

200 + 20 a MiB sent

| param | type |   |   |
|---|---|---|---|
| filter | "all" | req |  |
| config | {encoding?, transactionDetails?, maxSupportedTransactionVersion?} | opt |  |

```
{"jsonrpc":"2.0","id":1,"method":"blockSubscribe","params":["all",{"encoding":"base64","transactionDetails":"signatures","maxSupportedTransactionVersion":1}]}
```

**answer**: subscription id, then notifications
