accountUnsubscribe RPC Method
매개변수
숫자
로딩 중...
반품
결과
부울
로딩 중...
요청
1import { address, createSolanaRpcSubscriptions } from '@solana/kit';23async function handleAccountNotifications() {4const rpcSubscriptions = createSolanaRpcSubscriptions('');5const abortController = new AbortController();67시도해 보세요 {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();67시도해 보세요 {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();
1const web3 = require("@solana/web3.js");2(async () => {3const solanaConnection = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/", {4wsEndpoint: "",5});6solanaConnection.removeAccountChangeListener(0);7})();8
1const web3 = require("@solana/web3.js");2(async () => {3const solanaConnection = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/", {4wsEndpoint: "",5});6solanaConnection.removeAccountChangeListener(0);7})();8
1import solana2import asyncio3from asyncstdlib import enumerate4from solana.rpc.websocket_api import connect5출처: 솔라나.공개 키 import PublicKey67async def main():8async with connect("") as websocket:9await websocket.account_subscribe(PublicKey('E645TckHQnDcavVv92Etc6xSWQaq8zzPtPRGBheviRAk'))10first_resp = await websocket.recv()11subscription_id = first_resp.result12async for idx, msg in enumerate(websocket):13if idx == 3:14중단15print(msg)16await websocket.account_unsubscribe(subscription_id)1718asyncio.run(main())
1import solana2import asyncio3from asyncstdlib import enumerate4from solana.rpc.websocket_api import connect5출처: 솔라나.공개 키 import PublicKey67async def main():8async with connect("") as websocket:9await websocket.account_subscribe(PublicKey('E645TckHQnDcavVv92Etc6xSWQaq8zzPtPRGBheviRAk'))10first_resp = await websocket.recv()11subscription_id = first_resp.result12async for idx, msg in enumerate(websocket):13if idx == 3:14중단15print(msg)16await websocket.account_unsubscribe(subscription_id)1718asyncio.run(main())
1wscat -c \2# wait for connection3{"id":1,"jsonrpc":"2.0","method": "accountUnsubscribe", "params": [0]}4
1wscat -c \2# wait for connection3{"id":1,"jsonrpc":"2.0","method": "accountUnsubscribe", "params": [0]}4
답변
1{2"jsonrpc": "2.0",3"result": true,4"id": 15}
1{2"jsonrpc": "2.0",3"result": true,4"id": 15}