programSubscribe
Subscribe to a program to receive notifications when the lamports or data for an account owned by the given program changes.
The optional dataSlice configuration limits the account data returned in each notification to a byte range. It does not change which accounts match the subscription or its filters.
Connection URL
wss://sol.nownodes.io/wss/{api_key}Open the WebSocket connection, then send one JSON-RPC request as a text frame.
Subscription request example
{
"jsonrpc": "2.0",
"id": 1,
"method": "programSubscribe",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
"encoding": "base64",
"commitment": "confirmed",
"dataSlice": {
"offset": 0,
"length": 32
},
"filters": [
{
"dataSize": 165
}
]
}
]
}dataSlice.offset is the starting byte offset (zero-based), and dataSlice.length is the maximum number of bytes to return. In this example, each matching account notification contains the first 32 bytes of account data.
filters are evaluated against the account data as defined by the filter. In particular, dataSize refers to the full account data size, not the length of the returned dataSlice.
Use a binary account-data encoding such as base58 or base64 with dataSlice. The account space field, when present, describes the full account data size; it is not the length of the returned slice.
Subscription acknowledgement
After accepting the subscription, the server sends a JSON-RPC response containing the subscription ID:
{
"jsonrpc": "2.0",
"result": 24040,
"id": 1
}Notification format
Program account updates are sent in separate programNotification messages. Each notification contains one matching account object, as returned by getProgramAccounts; account.data contains only the requested slice when dataSlice is specified.
Base64 notification example (dataSlice: offset 0, length 32)
{
"jsonrpc": "2.0",
"method": "programNotification",
"params": {
"result": {
"context": {
"slot": 5208469
},
"value": {
"pubkey": "H4vnBqifaSACnKa7acsxstsY1iV1bvJNxsCY7enrd1hq",
"account": {
"data": [
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"base64"
],
"executable": false,
"lamports": 33594,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 636,
"space": 165
}
}
},
"subscription": 24040
}
}The example's data value represents 32 returned bytes. The space value remains the full account data size.
Body
jsonrpcstring2.0requiredJSON-RPC protocol version.
idinteger | stringrequiredClient request identifier.
methodstringprogramSubscriberequiredSolana WebSocket subscription method.
paramsArray<string | object>requiredPositional parameters: program ID, then optional program subscription configuration.
Parameters
api_keystringrequiredpathYour NOWNodes API key.
Response
WebSocket subscription acknowledgement message. This is not a program update notification; updates arrive later as programNotification messages.