---
id: HS0112
title: "Log mentions filter behavior"
url: https://carbium.sh/library/howsolana/log-mentions-filter-behavior
collection: How to use Solana
category: WebSocket
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Log mentions filter behavior

A short TypeScript file subscribes to one address with a logsSubscribe mentions filter, counts how many notifications print that address in their log lines, and reads three transactions back to show the address was an account of each one.

## What the filter matches

The answer is no. A `mentions` filter on `logsSubscribe` does not search the log text for your address. It matches transactions that list the address among their accounts, and a program is free to run without ever printing that account.

That difference decides what you receive. A `transferChecked` instruction lists the mint and both token accounts, yet the Token program logs only an instruction name and some compute unit counts. A subscription on the mint address still fires for that transfer, and a text search of the notification for the address string finds nothing.

On Carbium, `logsSubscribe` streams transaction logs, either all of them or only those that mention an address. Each notification holds the signature, an `err` field that is null on success, and the log lines of the whole transaction, including lines from programs that have nothing to do with your address.

| Situation | Notification arrives | Address in the log text |
|---|---|---|
| Transaction lists the address as an account, program logs it | Yes | Yes |
| Transaction lists the address as an account, no program logs it | Yes | No |
| A program prints the address text but the transaction does not list it as an account | No | Yes, but you never see it |
| Transaction fails with the address listed | Yes, with `err` set | Depends on how far it ran |

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips TypeScript types on load. Pass an address as the first argument, or leave it out to watch the USDC mint, which turns up in many transactions every second.

`main.ts` (run: `node main.ts [address]`)

```ts
// HS0112 · Log mentions filter behavior
// https://carbium.sh/library/howsolana/log-mentions-filter-behavior
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, signature } from "@solana/kit";
const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY first.");
  process.exit(1);
}
const target = address(process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key } }),
);
const wsUrl = new URL(process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh");
wsUrl.searchParams.set("api-key", key);

const asText = (v: unknown) => JSON.stringify(v, (_k, x) => (typeof x === "bigint" ? x.toString() : x));
let logged = 0;
let notLogged = 0;
let checked = 0;

async function readBack(sig: string) {
  try {
    const tx = await rpc.getTransaction(signature(sig), { encoding: "json", maxSupportedTransactionVersion: 1 }).send();
    console.log(`  read back ${sig.slice(0, 12)}: ${tx === null ? "not indexed yet" : asText([tx.transaction.message.accountKeys, tx.meta?.loadedAddresses]).includes(target) ? "in account list" : "address not found"}`);
  } catch (e) {
    console.error(`  read back failed for ${sig.slice(0, 12)}: ${e instanceof Error ? e.message : String(e)}`);
  }
}

const ws = new WebSocket(wsUrl);
ws.addEventListener("open", () => {
  ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "logsSubscribe", params: [{ mentions: [target] }, { commitment: "confirmed" }] }));
});
ws.addEventListener("message", (ev) => {
  const msg = JSON.parse(String(ev.data));
  if (msg.error) {
    console.error(`subscription refused: ${msg.error.message}`);
    return;
  }
  if (msg.method !== "logsNotification") return;
  const { context, value } = msg.params.result;
  const inLogs = ((value.logs ?? []) as string[]).some((l) => l.includes(target));
  if (inLogs) logged++;
  else notLogged++;
  console.log(`slot=${context.slot} ${value.err ? "failed" : "ok"} address in logs: ${inLogs ? "yes" : "no"} ${String(value.signature).slice(0, 12)}`);
  if (checked < 3) {
    checked++;
    void readBack(value.signature);
  }
});
setTimeout(() => {
  console.log(`summary for ${target}: logged=${logged} not logged=${notLogged}`);
  ws.close();
  setTimeout(() => process.exit(0), 1500);
}, 20_000);
```

For 20 seconds the file listens at confirmed commitment and counts each notification into one of two buckets: the address text appears in the log lines, or it does not. For the first three notifications it also calls `getTransaction` and searches the returned account keys and lookup table addresses for the address, which shows the address was an account of that transaction whatever the logs say.

The `getTransaction` call passes `maxSupportedTransactionVersion: 1`. A transaction can be read back as null for a moment after its notification, so the file prints that outcome instead of treating it as an error.

## Reading the output

A run against a busy mint prints a line per notification and a summary. The second bucket is the point of the exercise.

- `logged` counts notifications whose log lines contain the address text.
- `not logged` counts notifications that carried no such text, and still arrived because the address was an account.
- `in account list` on a read-back line confirms the match came from the transaction's accounts.

On a mint, expect most lines in the second bucket. On a program id the split is different, because the runtime itself writes `Program <id> invoke [1]` for every program it runs, so a subscription on a program address sees its own id in nearly every transaction.

> Subscribing to a program id with mentions is the usual way to follow a program, and it works because programs appear in the account list of every transaction that calls them.

## Filtering the way you meant to

If you wanted only transactions where a program printed something specific, the `mentions` filter is the first cut and your own code is the second. Check the log lines for the text you care about and drop the rest.

If you wanted every transaction that touches a wallet, the filter already does that. A plain SOL wallet is the case worth knowing: `accountSubscribe` sends nothing for it, so follow it with `logsSubscribe` mentions and read the amount with `getBalance`.

The filter takes one address in the list. To watch several addresses, open one subscription each. For filtering on the log text inside the notification, see [Instruction log filter](https://carbium.sh/library/howsolana/instruction-log-filter).

## On Carbium

A subscription with a mentions filter opens at 25 credits, then costs 20 credits per MiB sent, as set out in [limits](https://carbium.sh/docs/limits). A refused subscription costs nothing. A busy mint can send a lot of log text, so the per-MiB part is what grows.

Connections and subscriptions are capped per account by plan, and Free carries 5 sockets. An account's keys share one budget, so a second key does not raise the cap.

The WebSocket takes the key as `?api-key=` in the URL, and the file sets it there. The read-back goes to the RPC endpoint with the key in the `x-api-key` header. Each `getTransaction` costs 50 cells, so the three calls in the file come to 150, while a watcher that fetched every notification on a busy mint would pay 50 cells for each of thousands.

## Where it ends

The file proves the match on a sample of three transactions in 20 seconds. It does not prove that no transaction touching the address was missed, and a quiet address may send nothing in the window, in which case the summary reads zero.

The log lines in a notification are the transaction's own and can be cut short by the runtime when a transaction logs a great deal, so a text search over them can miss an address that a program did print.

A slot at processed commitment can be dropped with its fork, so a notification at a low commitment can describe a transaction that never lands. The file asks for confirmed, and a payment check should wait for it or ask again with `getSignatureStatuses`.

A socket that drops loses its subscriptions, and the file does not reconnect or backfill. For that, see [Multi-address deposit monitor](https://carbium.sh/library/blockchainideas/multi-address-deposit-monitor).

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The summary shows zero notifications. | The address was quiet for the 20 seconds. Pass a busy address such as a major mint, or lengthen the timer in the file. |
| No notification contains the address text and you conclude the filter is broken. | The filter matches the transaction's account list, so text in the logs is not the test. The read-back lines show `in account list` for those transactions. |
| The read-back prints `not indexed yet`. | The transaction was not yet readable when the call ran. Retry after a short wait, and use `maxSupportedTransactionVersion: 1` so a v1 transaction does not answer -32015. |
| `subscription refused` appears on connect. | Subscription counts are capped per account by plan, so close other sockets or move up a plan. A refused subscription costs no credits. |
| A plain SOL wallet gets nothing from `accountSubscribe`. | Use `logsSubscribe` with `mentions` for the wallet and read the amount with `getBalance`. |

## Questions

### Does the mentions address have to appear in the logs?

No. The filter matches the transaction's account list. A transaction that lists the address and prints nothing about it still sends a notification.

### Are failed transactions sent?

Yes. The notification arrives with `err` set and whatever logs ran before the failure.

### Can I pass several addresses in one mentions filter?

Pass one address per subscription. For a list, open one subscription each and keep a record of which subscription id belongs to which address.

### Is the notification the full transaction?

No. It holds the signature, the `err` field and the log lines. Fetch the rest with `getTransaction` when you need the accounts or the instructions.

## Related

- [Instruction log filter](https://carbium.sh/library/howsolana/instruction-log-filter) (How to use Solana, HS0067)
- [Multi-address deposit monitor](https://carbium.sh/library/blockchainideas/multi-address-deposit-monitor) (Blockchain ideas, BI0006)
- [carbium.sh/docs/websocket](https://carbium.sh/docs/websocket)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
