accountUnsubscribe RPC Method
Parameters
number
Loading...
Returns
result
boolean
Loading...
Request
1import { address, createSolanaRpcSubscriptions } from '@solana/kit';23async function handleAccountNotifications() {4const rpcSubscriptions = createSolanaRpcSubscriptions('');5const abortController = new AbortController();67try {89const accountNotifications = await rpcSubscriptions10.accountNotifications(address('AxZfZWeqztBCL37Mkjkd4b8Hf6J13WCcfozrBY6vZzv3'), { commitment: 'confirmed' })11.subscribe({ abortSignal: abortController.signal });1213let previousOwner = null;1415// Consume messages16for await (const notification of accountNotifications) {17const {18value: { owner },19} = notification;2021// Check if owner has changed22if (previousOwner && owner !== previousOwner) {23console.log('Owner has changed, aborting subscription.');24abortController.abort();25break;26} else {27console.log('Notification:', notification);28}2930previousOwner = owner;31}32} catch (e) {33console.error('Error while handling notifications:', e);34} finally {35console.log('Unsubscribed from account notifications');36}37}3839handleAccountNotifications();
1import { address, createSolanaRpcSubscriptions } from '@solana/kit';23async function handleAccountNotifications() {4const rpcSubscriptions = createSolanaRpcSubscriptions('');5const abortController = new AbortController();67try {89const accountNotifications = await rpcSubscriptions10.accountNotifications(address('AxZfZWeqztBCL37Mkjkd4b8Hf6J13WCcfozrBY6vZzv3'), { commitment: 'confirmed' })11.subscribe({ abortSignal: abortController.signal });1213let previousOwner = null;1415// Consume messages16for await (const notification of accountNotifications) {17const {18value: { owner },19} = notification;2021// Check if owner has changed22if (previousOwner && owner !== previousOwner) {23console.log('Owner has changed, aborting subscription.');24abortController.abort();25break;26} else {27console.log('Notification:', notification);28}2930previousOwner = owner;31}32} catch (e) {33console.error('Error while handling notifications:', e);34} finally {35console.log('Unsubscribed from account notifications');36}37}3839handleAccountNotifications();
Response
1{2"jsonrpc": "2.0",3"result": true,4"id": 15}
1{2"jsonrpc": "2.0",3"result": true,4"id": 15}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free