accountSubscribe

accountSubscribe WebSocket Method

post

Subscribe to an account to receive notifications when the lamports or data for a given account public key changes. Returns a subscription ID that can be used to unsubscribe. This method establishes a persistent WebSocket connection that will send real-time notifications whenever the specified account's state changes on the blockchain.

Authorizations
Body

Request object for subscribing to account changes via WebSocket

jsonrpcstring · enumRequired

JSON-RPC protocol version

Example: 2.0Possible values:
idone ofRequired

Request identifier that will be returned in the response

Example: 1
stringOptional
or
numberOptional
methodstring · enumRequired

The WebSocket method name

Example: accountSubscribePossible values:
Responses
101

WebSocket notification for account changes

application/json
post
const ws = new WebSocket('wss://public.rpc.solanavibestation.com');

ws.onopen = function() {
  // Subscribe to account changes
  ws.send(JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'accountSubscribe',
    params: [
      'CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12',
      { commitment: 'finalized', encoding: 'jsonParsed' }
    ]
  }));
};

ws.onmessage = function(event) {
  const data = JSON.parse(event.data);
  
  if (data.method === 'accountNotification') {
    console.log('Account changed:', data.params);
  } else if (data.result) {
    console.log('Subscription ID:', data.result);
  }
};
{
  "jsonrpc": "2.0",
  "method": "accountNotification",
  "params": {
    "result": {
      "context": {
        "slot": 123456789
      },
      "value": {
        "data": [
          "",
          "base64"
        ],
        "executable": false,
        "lamports": 1000000000,
        "owner": "11111111111111111111111111111111",
        "rentEpoch": 361
      }
    },
    "subscription": 23784
  }
}

Last updated