Account and Program Subscriptions

accountSubscribe

WebSocket - JSON-RPC

Subscribe to an account to receive notifications when the lamports or data for a given account public key changes.

Parameters

stringrequired

Account Pubkey, base-58 encoded.

object

Configuration object:

  • encoding (string) - base58, base64, base64+zstd, jsonParsed
  • commitment (string) - commitment level

Request

bash
wscat -c wss://ws.sol.cubestech.online -H "x-api-key: YOUR_API_KEY"
> {"jsonrpc":"2.0","id":1,"method":"accountSubscribe","params":["CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12",{"encoding":"jsonParsed","commitment":"finalized"}]}
json
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "accountSubscribe",
  "params": [
    "CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12",
    {
      "encoding": "jsonParsed",
      "commitment": "finalized"
    }
  ]
}

Response

json
{
  "jsonrpc": "2.0",
  "result": 23784,
  "id": 1
}

The result value is the subscription ID used to unsubscribe.

Notification Format

result.valueobject
properties
lamportsinteger
Account balance in lamports.
datastring|object
Account data in requested encoding.
ownerstring
Program that owns this account.
executableboolean
Whether the account contains a program.
rentEpochinteger
Epoch at which rent is next due.

accountUnsubscribe

WebSocket - JSON-RPC

Cancel account change notifications.

integerrequired

Subscription ID returned by accountSubscribe.

bash
wscat -c wss://ws.sol.cubestech.online -H "x-api-key: YOUR_API_KEY"
> {"jsonrpc":"2.0","id":1,"method":"accountUnsubscribe","params":[23784]}
json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "accountUnsubscribe",
  "params": [23784]
}
json
{
  "jsonrpc": "2.0",
  "result": true,
  "id": 1
}

programSubscribe

WebSocket - JSON-RPC

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

Parameters

stringrequired

Program ID, base-58 encoded.

object

Configuration object:

  • encoding (string) - base58, base64, base64+zstd, jsonParsed
  • commitment (string) - commitment level
  • filters (array) - filter results using memcmp or dataSize

Request

bash
wscat -c wss://ws.sol.cubestech.online -H "x-api-key: YOUR_API_KEY"
> {"jsonrpc":"2.0","id":1,"method":"programSubscribe","params":["11111111111111111111111111111111",{"encoding":"base64","commitment":"finalized"}]}
json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "programSubscribe",
  "params": [
    "11111111111111111111111111111111",
    {
      "encoding": "base64",
      "commitment": "finalized"
    }
  ]
}

Response

json
{
  "jsonrpc": "2.0",
  "result": 24040,
  "id": 1
}

Notification Format

result.valueobject
properties
pubkeystring
Account public key.
accountobject
properties
lamportsinteger
Account balance.
datastring|object
Account data in requested encoding.
ownerstring
Program that owns this account.
executableboolean
Whether account contains a program.
rentEpochinteger
Next rent-due epoch.

programUnsubscribe

WebSocket - JSON-RPC

Cancel program-owned account notifications.

integerrequired

Subscription ID returned by programSubscribe.

bash
wscat -c wss://ws.sol.cubestech.online -H "x-api-key: YOUR_API_KEY"
> {"jsonrpc":"2.0","id":1,"method":"programUnsubscribe","params":[0]}
json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "programUnsubscribe",
  "params": [0]
}
json
{
  "jsonrpc": "2.0",
  "result": true,
  "id": 1
}