accountSubscribe
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 · enumRequiredExample:
JSON-RPC protocol version
2.0
Possible values: idone ofRequiredExample:
Request identifier that will be returned in the response
1
stringOptional
numberOptional
methodstring · enumRequiredExample:
The WebSocket method name
accountSubscribe
Possible values: Responses
101
WebSocket notification for account changes
application/json
200
Subscription successfully created
application/json
400
Bad Request - Invalid parameters
application/json
401
Unauthorized
text/plain
403
Forbidden
text/plain
429
Too Many Requests
text/plain
500
Internal Server Error
text/plain
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