programSubscribe

All the specifications for programSubscribe Websocket Method on Solana

Subscribe to a program to receive notifications when the lamports or data for an account owned by the given program changes.

Parameters required for this RPC call

  • The address of the program (pubkey), as a base-58 encoded string.

  • configuration object: This contains the following parameters, all are optional fields.

    • commitment: The commitment describes how finalized a block is at that point in time. Commitment levels processed, confirmed and finalized are supported, defaults to finalized.

    • filters: Filter results using various filter objects. The resultant account must meet ALL filter criteria to be included in the returned results

    • encoding: Encoding format for Account data

      • base58 is slow.

      • jsonParsed encoding attempts to use program-specific state parsers to return more human-readable and explicit account state data

      • If jsonParsed is requested but a parser cannot be found, the field falls back to binary encoding, detectable when the data field is type string.

      • Supports: base58 , base64 , base64+zstd , jsonParsed

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "programSubscribe",
  "params": [
    "11111111111111111111111111111111",
    {
      "encoding": "base64",
      "filters": [{ "dataSize": 80 }]
    }
  ]
}

Notification Format:

The notification format is a single program account object as seen in the getProgramAccounts RPC HTTP method.

{
  "jsonrpc": "2.0",
  "method": "programNotification",
  "params": {
    "result": {
      "context": {
        "slot": 5208469
      },
      "value": {
        "pubkey": "H4vnBqifaSACnKa7acsxstsY1iV1bvJNxsCY7enrd1hq",
        "account": {
          "data": [
            "11116bv5nS2h3y12kD1yUKeMZvGcKLSjQgX6BeV7u1FrjeJcKfsHPXHRDEHrBesJhZyqnnq9qJeUuF7WHxiuLuL5twc38w2TXNLxnDbjmuR",
            "base58"
          ],
          "executable": false,
          "lamports": 33594,
          "owner": "11111111111111111111111111111111",
          "rentEpoch": 636,
          "space": 80
        }
      }
    },
    "subscription": 24040
  }
}

Last updated

Was this helpful?