logsSubscribe

logsSubscribe WebSocket Method

post

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.

Authorizations
Body

Request object for subscribing to transaction logs via WebSocket

jsonrpcstring · enumRequired

JSON-RPC protocol version

Example: 2.0Possible values:
idone ofRequired

Request identifier that will be returned in the response

Example: 1
stringOptional
or
numberOptional
methodstring · enumRequired

The WebSocket method name

Example: logsSubscribePossible values:
Responses
101

WebSocket notification for transaction logs

application/json
post
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