logsSubscribe
Subscribe to transaction logging to receive notifications when transactions occur that match specified filter criteria. This method establishes a persistent WebSocket connection that will send real-time log notifications whenever transactions matching your filters are processed by the network. You can filter by all transactions, transactions with votes, or transactions mentioning specific accounts.
Request object for subscribing to transaction logs via WebSocket
JSON-RPC protocol version
2.0
Possible values: Request identifier that will be returned in the response
1
The WebSocket method name
logsSubscribe
Possible values: WebSocket notification for transaction logs
Subscription successfully created
Bad Request - Invalid parameters
Unauthorized
Forbidden
Too Many Requests
Internal Server Error
const ws = new WebSocket('wss://public.rpc.solanavibestation.com');
ws.onopen = function() {
// Subscribe to all transaction logs (except votes)
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'logsSubscribe',
params: [
'all',
{ commitment: 'finalized' }
]
}));
// Subscribe to Token Program logs
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 2,
method: 'logsSubscribe',
params: [
{ mentions: ['TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'] },
{ commitment: 'confirmed' }
]
}));
};
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
if (data.method === 'logsNotification') {
const { signature, err, logs } = data.params.result.value;
console.log('Transaction:', signature);
console.log('Status:', err ? 'Failed' : 'Success');
console.log('Logs:', logs);
} else if (data.result) {
console.log('Subscription ID:', data.result);
}
};
{
"jsonrpc": "2.0",
"method": "logsNotification",
"params": {
"result": {
"context": {
"slot": 5208469
},
"value": {
"signature": "5h6xBEauJ3PK6SWCZ1PGjBvj8vDdWG3KpwATGy1ARAXFSDwt8GFXM7W5Ncn16wmqokgpiKRLuS83KUxyZyv2sUYv",
"err": null,
"logs": [
"SBF program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success"
]
}
},
"subscription": 24040
}
}
Last updated