library / How to use Solana / History and parsing / HS0161
Program event log query
Solana has no eth_getLogs call. Run this file to list a program's newest signatures, read each transaction's log messages and print the lines that match, with getSignaturesForAddress and getTransaction only.
What replaces the log filter
Ethereum's eth_getLogs takes a block range and an address, then returns every event whose topics match. Solana has no call with that shape. A program writes its messages into each transaction's log, and the node stores those messages in the transaction's metadata. So the query becomes two steps: list the newest signatures that touch a program with getSignaturesForAddress, then read the log messages of each one with getTransaction.
The filter is plain text. Solana log lines carry no indexed topics, so the match is a substring test on each line. The SPL Token program prints Program log: Instruction: Transfer for a transfer, and the default needle matches that wording. The same program also has a TransferChecked instruction, and the substring catches that line too. Pass a longer needle to match one instruction only.
The window differs too. eth_getLogs takes block numbers. This file takes a count of signatures, newest first, capped at 20. Signature paging covers the cursor for walking further back. On Carbium the address index keeps 30 days at most, so older events fall outside this query.
The code
Install @solana/kit at 8.6.0, export CARBIUM_KEY and run the file with Node 24, which strips the types on load. With no arguments it reads the five newest SPL Token signatures and prints the transfer lines. The first argument is the program address, the second the substring, and the third the signature count.
// HS0161 · Program event log query// https://carbium.sh/library/howsolana/program-event-log-query// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport,} from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),);const TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";const [programArg = TOKEN_PROGRAM, needle = "Instruction: Transfer", countArg = "5"] = process.argv.slice(2);const program = address(programArg);const count = Math.min(Number(countArg) || 5, 20);const signatures = await rpc .getSignaturesForAddress(program, { limit: count, commitment: "confirmed" }) .send();console.log(`${signatures.length} newest signatures for ${program}`);const reads = await Promise.allSettled( signatures.map((s) => rpc .getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: "confirmed", }) .send(), ),);for (const [i, read] of reads.entries()) { const entry = signatures[i]; if (!entry) continue; if (read.status === "rejected") { console.log(`${entry.signature} failed: ${String(read.reason)}`); continue; } if (!read.value) { console.log(`${entry.signature} null: listed, but not in the ledger`); continue; } const logs = read.value.meta?.logMessages ?? []; const hits = logs.filter((line) => line.includes(needle)); console.log(`slot ${entry.slot} ${entry.signature}: ${hits.length} matching lines`); for (const line of hits) console.log(` ${line}`);}
run: node main.ts
The transport sends every call to https://services.carbium.sh with the key in the x-api-key header, and the client is built once. The signature list is one call. Each transaction is then read with getTransaction inside one Promise.allSettled, so one failed read does not stop the rest. Every read passes maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and the node answers -32015 without it.
A null for a listed signature is printed and skipped. The file writes nothing and signs nothing, and the key stays in the environment. Each transaction's log lines come from meta.logMessages, so the file never decodes instruction data. The cost is 50 cells for the signature list and 50 per transaction, so the five-signature default runs 300 cells.
Following new events
A query shows what already happened. To follow a program as its transactions land, open a WebSocket to wss://services.carbium.sh with the key as ?api-key=<YOUR_KEY>, then send logsSubscribe with a mentions filter for the program address. Each notification carries the signature and the log lines of one transaction, so the same substring test applies. The JSON-RPC server defaults to finalized, so set confirmed in the filter when you want the newest events.
Run the query and the subscription with the same needle and the same commitment. After a restart, the query reads the signatures the stream missed, and the two outputs line up line for line.
Reading the output
| Field | Where it comes from | Meaning |
|---|---|---|
| signature | getSignaturesForAddress | The base58 id of the transaction, the key to read it again. |
| slot | getSignaturesForAddress | The slot the node recorded the transaction in. |
| logMessages | getTransaction, meta | The program's log lines in order, including the invoke and success lines around each call. |
| err | getSignaturesForAddress | null when the transaction succeeded. Failed transactions still carry logs. |
Each program call writes an invoke [depth] line, then its own messages, then a success or failed line. The nesting shows in the list. Solana also cuts very long logs and inserts a Log truncated line, so a match can go missing from a large transaction.
Where it ends
A call here takes a count of signatures from the newest end of one program's history. Walking to an older window means paging with the signature cursor, and the address index keeps 30 days at most. An empty page past 30 days marks that age limit. Older signatures the index still lists can return null from getTransaction, because the validator's ledger no longer holds them.
The match is a text test. A program may log the same words for an action that is no transfer, and a program that logs nothing leaves nothing to match. The file cannot see token amounts or account changes unless the program prints them. For amounts, read preTokenBalances and postTokenBalances from the same transaction read.
Block scans over a slot range are a separate job. getBlock takes the same version argument, so the rule holds there too, but this file does not scan blocks. Carbium serves RPC methods by name, and a name Solana does not have, such as eth_getLogs or getLogs, answers -32601 method not found.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| Error -32015 from getTransaction for a signature you know is recent. | Send encoding: "json" with maxSupportedTransactionVersion: 1. Without the version argument the node refuses a v1 transaction, and a refused call is not charged. |
| getTransaction returns null for a signature from the list. | The address index lists older signatures than the ledger still holds. The file prints the line and moves on. Count it in your report, and do not retry it as an error. |
| Error -32601 method not found, for a call named getLogs. | Solana has no log filter method. Use getSignaturesForAddress and getTransaction, as this file does, or logsSubscribe for live events. Do not retry the name. |
| HTTP 429 with a retry-after hint. | Wait the seconds in the header and try once more. On Free the signature list runs at 0.24 req/s, so space repeated runs by several seconds. |
| 401 with UNKNOWN_KEY. | Attach the whole key in the x-api-key header. The file reads CARBIUM_KEY and sends it unchanged, so check that the variable holds the full key. |
| No match, though the transaction is a transfer. | Print logMessages for that signature and read the wording. Look for a Log truncated line, which means the match may be cut off. |
Questions
Is there an eth_getLogs equivalent in Solana?
Not as one call. Solana splits the job in two: list a program's signatures, then read each transaction's log messages. For live events, use logsSubscribe.
Can I ask for every event in a block range?
This file cannot. Scanning slots with getBlock is the route for a range, and it needs maxSupportedTransactionVersion 1 as well. The signature list covers only the newest transactions of one address.
How far back can the query go?
The address index keeps 30 days. Past that an empty page marks the limit, and some older listed signatures still return null.
Why does my filter also match TransferChecked?
The needle is a substring of each log line. Pass a longer string, such as Instruction: TransferChecked, to match that instruction alone.
Does the run need a wallet or a private key?
No. The file only reads. The Carbium key identifies your account to the RPC.