logsSubscribe
Subscribes to transaction log messages, streaming the logs of every transaction — or only those that mention a given account — as they are committed.
logsSubscribe streams the log output of transactions as they execute. Each
logsNotification delivers one transaction's worth of logs: the transaction
signature, its err status (null on success), and the ordered logs
array — the same Program ... invoke / Program log: ... lines you see in
getTransaction metadata, but pushed to you in real time instead of fetched
after the fact.
The first parameter is a filter. The string "all" subscribes to every
non-vote transaction on the cluster; "allWithVotes" includes vote
transactions too (a torrent — rarely what you want); and
{"mentions": ["<pubkey>"]} narrows the stream to transactions that reference
a specific account. The mentions array accepts exactly one pubkey per
subscription — passing several is an error, so open one subscription per
address you track. The optional config object takes a commitment level
(processed, confirmed — the default — or finalized).
This is the workhorse method for event-driven indexing: watching a program id
for every interaction with your protocol, detecting new SPL token mints by
watching the token program, following a DEX pool address for swaps, or
alerting on any transaction that touches a treasury wallet. Since program
events on Solana are usually emitted as log lines, logsSubscribe on a
program id is the closest native equivalent to an EVM event subscription.
Mind the failure modes. A mentions filter matches any reference to the
account — including failed transactions, so check err before acting. Logs
can be truncated when a transaction exceeds the node's log budget (Log truncated appears in the array). And like all Pub/Sub subscriptions, the
stream dies with the WebSocket session: on reconnect you must resubscribe and
backfill the gap with getSignaturesForAddress if you cannot afford to miss
events. Stop the stream with logsUnsubscribe.
Parameters
Positional params array: [filter, config?].
filterstring | objectrequired"all", "allWithVotes", or {"mentions": ["<base-58 pubkey>"]} (exactly one pubkey).configobjectoptionalcommitmentstringoptionalprocessed, confirmed (default), or finalized.Response
Subscribe ack:
Each matching transaction is pushed as a logsNotification:
{
"jsonrpc": "2.0",
"method": "logsNotification",
"params": {
"subscription": 41902,
"result": {
"context": { "slot": 348392060 },
"value": {
"signature": "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW",
"err": null,
"logs": [
"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]",
"Program log: Instruction: Transfer",
"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success"
]
}
}
}
}result (on ack)integerlogsUnsubscribe.params.result.context.slotintegerparams.result.value.signaturestringparams.result.value.errobject | nullnull on success, otherwise the TransactionError.params.result.value.logsarray of stringErrors
| Code | Meaning | When it happens |
|---|---|---|
-32602 | Invalid params | Malformed filter — e.g. more than one pubkey in mentions. |
4003 | forbidden | Your tier is below basic (tier_insufficient; the frame carries required_tier). |
4029 | rate_limited | Subscribe rate exceeded for your tier. |
Notes
- One pubkey per
mentionsfilter — open multiple subscriptions on the same socket to track multiple addresses. - Failed transactions match too: always branch on
value.err. - Gaps on reconnect: the stream has no replay; backfill with
getSignaturesForAddress+getTransactionafter resubscribing. - Related methods:
logsUnsubscribe,programSubscribe(account-state view of the same activity), andsignatureSubscribe(status of one known transaction).