Skip to main content

accountUnsubscribe RPC Method

Loading...

Updated on
Apr 30, 2025

accountUnsubscribe RPC Method

Parameters

number
Loading...

Returns

result
boolean
Loading...
Request
1
import { address, createSolanaRpcSubscriptions } from '@solana/kit';
2
3
async function handleAccountNotifications() {
4
const rpcSubscriptions = createSolanaRpcSubscriptions('');
5
const abortController = new AbortController();
6
7
try {
8
9
const accountNotifications = await rpcSubscriptions
10
.accountNotifications(address('AxZfZWeqztBCL37Mkjkd4b8Hf6J13WCcfozrBY6vZzv3'), { commitment: 'confirmed' })
11
.subscribe({ abortSignal: abortController.signal });
12
13
let previousOwner = null;
14
15
// Consume messages
16
for await (const notification of accountNotifications) {
17
const {
18
value: { owner },
19
} = notification;
20
21
// Check if owner has changed
22
if (previousOwner && owner !== previousOwner) {
23
console.log('Owner has changed, aborting subscription.');
24
abortController.abort();
25
break;
26
} else {
27
console.log('Notification:', notification);
28
}
29
30
previousOwner = owner;
31
}
32
} catch (e) {
33
console.error('Error while handling notifications:', e);
34
} finally {
35
console.log('Unsubscribed from account notifications');
36
}
37
}
38
39
handleAccountNotifications();
Response
1
{
2
"jsonrpc": "2.0",
3
"result": true,
4
"id": 1
5
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free