Skip to main content

logsUnsubscribe RPC Method

Loading...

Updated on
Apr 30, 2025

logsUnsubscribe RPC Method

Parameters

number
Loading...

Returns

result
boolean
Loading...
Request
1
import { address, createSolanaRpcSubscriptions } from '@solana/kit';
2
3
const rpcSubscriptions = createSolanaRpcSubscriptions('');
4
5
async function main() {
6
const publicKeyString = address('E645TckHQnDcavVv92Etc6xSWQaq8zzPtPRGBheviRAk');
7
const abortController = new AbortController();
8
9
const subscription = await rpcSubscriptions
10
.logsNotifications({ mentions: [publicKeyString] })
11
.subscribe({ abortSignal: abortController.signal });
12
13
let logCount = 0;
14
15
try {
16
for await (const notification of subscription) {
17
logCount += 1;
18
console.log(`Log #${logCount}: `, notification);
19
20
if (logCount > 3) {
21
console.log("Log count exceeded 3, unsubscribing...");
22
break;
23
}
24
}
25
} catch (e) {
26
console.error("Error in logs subscription:", e);
27
} finally {
28
abortController.abort();
29
console.log('Aborted subscription handling.');
30
}
31
}
32
33
main();
34
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