in-solana by Supanode

programSubscribe — Solana WebSocket Method

programSubscribe sends a notification whenever any account owned by the specified program changes. This is the streaming equivalent of getProgramAccounts — instead of polling, you receive updates as they happen.

Subscribe request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "programSubscribe",
  "params": [
    "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
    {
      "encoding": "jsonParsed",
      "commitment": "confirmed",
      "filters": [
        { "dataSize": 165 }
      ]
    }
  ]
}

Notification format

{
  "jsonrpc": "2.0",
  "method": "programNotification",
  "params": {
    "result": {
      "context": { "slot": 123456789 },
      "value": {
        "pubkey": "9xQeW...",
        "account": {
          "lamports": 2039280,
          "data": ["...", "base64"],
          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "executable": false,
          "rentEpoch": 361,
          "space": 165
        }
      }
    },
    "subscription": 42
  }
}

Filters

Use filters to reduce notification volume:

FilterExampleEffect
dataSize{"dataSize": 165}Only accounts of exact size (165 = Token Account)
memcmp{"memcmp": {"offset": 32, "bytes": "<owner_pubkey>"}}Match bytes at offset

Without filters, you receive notifications for every account owned by the program. For the Token program, this means millions of accounts.

FAQ

How is this different from accountSubscribe? accountSubscribe watches one specific account. programSubscribe watches all accounts owned by a program, with optional filters.

Can I use multiple filters? Yes. Filters are combined with AND logic — all filters must match for a notification to be sent.

Is programSubscribe suitable for tracking all token transfers? For low-to-moderate volume, yes. For high-volume monitoring (tracking all SPL Token activity on mainnet), consider gRPC streaming which handles the throughput more efficiently.

Parameters

ParameterTypeRequiredDescriptionDefault
programIdstringYesProgram pubkey as base-58 encoded string—
configobjectNoConfiguration object with commitment, encoding, and filters (dataSize, memcmp)—

Updated: