TriportRPC

programSubscribe

Last updated:

programSubscribe is the streaming counterpart of getProgramAccounts: you name a program id, and the server pushes a programNotification every time the lamports or data of any account owned by that program change. Each notification identifies the changed account by pubkey and carries its full new state in account — the same shape getAccountInfo returns — so you can maintain a live mirror of a program's account set without rescanning it.

Because popular programs own millions of accounts, the config object's filters array is what makes this method practical. Two filter kinds can be combined (an account must match all of them): dataSize keeps only accounts whose data is exactly N bytes (e.g. 165 for SPL token accounts), and memcmp keeps accounts whose bytes at a given offset equal a base-58 bytes needle — the standard trick for matching a specific field, such as a token account's owner at offset 32 or a mint at offset 0. commitment and encoding behave as in accountSubscribe; jsonParsed is worth requesting for well-known programs so notifications arrive pre-decoded.

Real-world uses: tracking every token account of a wallet (token program + memcmp on the owner field), watching a DEX program's pool accounts for reserve changes, following an on-chain order book, or monitoring a lending protocol's obligation accounts for liquidation thresholds. It also fires when new accounts are created under the program, which makes it a natural new-market or new-mint detector.

Gotchas: an unfiltered subscription on a busy program can flood a connection — always start from the tightest dataSize/memcmp combination you can. Filters are fixed at subscribe time; to change them, open a new subscription and drop the old one with programUnsubscribe. And the stream is session-scoped: a reconnect requires resubscribing, with a getProgramAccounts snapshot to re-sync state you may have missed.

Parameters

This method takes no parameters.

Returns

programSubscribe return value
FieldType
resultobject

Examples

curl https://triport.io/sol \
  -X POST -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <api-key>' \
  -d '{"id":1,"method":"programSubscribe","params":[],"jsonrpc":"2.0"}'
const res = await fetch("https://triport.io/sol", {
  method: "POST",
  headers: { "Content-Type": "application/json", Authorization: "Bearer <api-key>" },
  body: JSON.stringify({
  "id": 1,
  "method": "programSubscribe",
  "params": [],
  "jsonrpc": "2.0"
}),
});
const data = await res.json();
import requests
resp = requests.post(
    "https://triport.io/sol",
    headers={"Authorization": "Bearer <api-key>"},
    json={"id":1,"method":"programSubscribe","params":[],"jsonrpc":"2.0"},
)
print(resp.json())

Usage

  1. Transport: WebSocket.
  2. Networks: mainnet, devnet, testnet.
  3. Credit cost: 1 per call.

FAQ

What does programSubscribe do?
Subscribes to a program by id and streams a notification whenever any account owned by that program changes, with optional size and byte-match filters.
How many credits does programSubscribe cost?
programSubscribe costs 1 credit(s) per call on Triport by default.
Is programSubscribe available over WebSocket?
Yes, programSubscribe supports WebSocket.