# logsSubscribe

> Streams program log output for transactions matching a filter, as each one lands.

Source: https://docs.constant-k.com/rpc/websocket/logssubscribe/

`logsSubscribe` is a lighter-weight alternative to `blockSubscribe` or `programSubscribe` for reacting to transaction outcomes and their log lines. `filter` selects which transactions are included: `"all"` for every non-vote transaction, `"allWithVotes"` to also include vote transactions (very high volume), or `{"mentions": ["<pubkey>"]}` for only transactions whose account list includes that one address — the mentions list must contain exactly one address; the node rejects more than one.

`commitment` trades notification speed against the chance a transaction's outcome still changes: a `processed` log line can belong to a transaction that later fails to reach `confirmed`.

- Transport: WebSocket, JSON-RPC 2.0 over `wss://ws-newyork.constant-k.com:1337/ws?api-key=YOUR_API_KEY`
- Category: Subscriptions
- Availability: Operator and above

## Parameters

`params` is a positional JSON array, in this order:

- `filter` (string | object, required): Which transactions to receive logs for.
  - `option 1` (string, optional, one of `all`, `allWithVotes`)
  - `option 2` (object, optional)
    - `mentions` (string[], required): Exactly one base58 pubkey; a list with more than one entry is rejected.
- `config` (object, optional): Optional subscription settings.
  - `commitment` (string, optional, one of `processed`, `confirmed`, `finalized`, default `"finalized"`): How settled the account/transaction state must be before the node acts on it. `processed` is fastest and can roll back; `finalized` is slowest and never rolls back.

## Result

- `result` (integer, optional): The subscription id, returned once in the initial RPC response. Passed to `logsUnsubscribe`, it cancels the stream.

## Notifications

Updates arrive as `logsNotification` messages. `result.value.signature` identifies the transaction, `result.value.err` is `null` on success or the transaction error object on failure, and `result.value.logs` is the ordered array of program log lines (`Program X invoke`, `Program log: ...`, `Program X success`, and so on).

- `params.result` (object, optional)
  - `context` (object, optional): Response context, including the slot the data was read at.
    - `slot` (integer, optional): Slot number this applies to.
  - `value` (object, optional): The requested data; see the fields below.
    - `signature` (string, optional): Base58 transaction signature.
    - `err` (object | null, optional): Null on success, or an error object/string describing the failure.
    - `logs` (string[], optional): Ordered program log lines emitted while the transaction executed.

## Unsubscribe

`logsUnsubscribe`, called with the subscription id, returns `true` once the subscription is removed.

## Example: Subscribe to logs mentioning the Token program

Request (send after connecting):

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "logsSubscribe",
  "params": [
    {
      "mentions": [
        "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
      ]
    },
    {
      "commitment": "confirmed"
    }
  ]
}
```

Response:

```json
{
  "jsonrpc": "2.0",
  "result": 26917947,
  "id": 1
}
```

Notification:

```json
{
  "jsonrpc": "2.0",
  "method": "logsNotification",
  "params": {
    "result": {
      "context": {
        "slot": 447946423
      },
      "value": {
        "signature": "1111111111111111111111111111111111111111111111111111111111111111",
        "err": null,
        "logs": [
          "Program ComputeBudget111111111111111111111111111111 invoke [1]",
          "Program ComputeBudget111111111111111111111111111111 success",
          "Program ComputeBudget111111111111111111111111111111 invoke [1]"
        ]
      }
    },
    "subscription": 26917947
  },
  "truncated": true
}
```

## Notes

- WebSocket access is included on the Operator plan and above; it is not available on Free.
- Concurrent connections are capped per API key: 10 on Operator, 50 on Blade Runner, 100 on Nexus.
- Subscribe and unsubscribe calls draw from the same global per-plan request-rate limit as HTTP calls: 50 req/s on Operator, 200 req/s on Blade Runner, 500 req/s on Nexus.
- Only subscription methods (the `*Subscribe` / `*Unsubscribe` family) are accepted on the WebSocket endpoint; standard request/response RPC methods must go over HTTPS instead.
- A `getHealth` request sent over the open socket on a regular interval serves as a keepalive; connections that go quiet can be dropped by intermediate load balancers.
- Each region has its own WebSocket hostname, for example `wss://ws-newyork.constant-k.com:1337/ws?api-key=YOUR_API_KEY`; every region is listed on the Endpoints page.
- Captured live from `wss://api.mainnet-beta.solana.com`; the real notification's `logs` array ran to about 90 lines from a multi-hop swap transaction and has been trimmed to 3 for this reference.

