---
id: BI0005
title: "Wallet activity tracker"
url: https://carbium.sh/library/blockchainideas/wallet-activity-tracker
collection: Blockchain ideas
category: Wallet watchers
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Wallet activity tracker

One logsSubscribe on Carbium's WebSocket, one getSignaturesForAddress for recent history and one getBalance give you a running list of every transaction that mentions a wallet, with its result and the wallet's balance on a line beside the rows.

## Who uses it

Two groups want the same list. The first holds funds in one address, a person or a small team, and wants to know the moment anything leaves it or arrives. The second is a support desk that gets the question "did my payment arrive?" and wants to answer with a signature and a result.

A hackathon team can demo it against any public address, since every transaction on Solana is readable by anyone. Point it at a busy one and live rows start at once. History and the live stream come from `services.carbium.sh` with one key.

## What it shows

Each transaction is one printed row. Rows from the two sources carry slightly different columns.

| Column | Where it comes from | Example |
|---|---|---|
| Source | `PAST` for a row from getSignaturesForAddress, `LIVE` for one from the socket | `LIVE` |
| Signature | `signature` in the history row or the logsNotification | the id you paste into an explorer |
| Result | `err` is null for success and an object for failure | `ok`, or `failed` with the error JSON |
| Time | `blockTime` on a history row; the tracker's own clock on a live row | `2026-11-22T09:14:03.000Z` |
| Balance | getBalance once after the history prints, then after a live row, at most every 5 seconds | `balance 0.0412 SOL` |

History rows come out oldest first, so the screen reads in time order. A live row prints when the transaction reaches `confirmed`, the level the code names on the subscription, the history page and the balance read.

## The build

The tracker is one file. It needs `@solana/kit` and what Node 24 ships, and it is read-only: no key pair, nothing signed, nothing sent. Run it as `node main.ts <wallet address>`.

1. Take the key from the `CARBIUM_KEY` environment variable and the address from the first command-line argument, and exit with a message if either is missing. `address()` from kit rejects a malformed string before any call goes out.
2. Create the RPC client once and reuse it for every call.
3. Open one [WebSocket](https://carbium.sh/docs#websocket) to `wss://services.carbium.sh` with the key as `?api-key=`. On open, send `logsSubscribe` with `{ mentions: [wallet] }` at `confirmed`. The first reply carries the subscription id, or an error if the subscription is refused, and a refusal is free.
4. When that reply confirms the subscription, call `getSignaturesForAddress` with a limit of 5 and print the rows oldest first as `PAST`, then read the balance once. Remember each signature in a Set. The stream is already open when the history is asked for, so no transaction falls between the two, and the Set drops the overlap.
5. On every `logsNotification`, skip a signature already in the Set, print a `LIVE` row with `ok` or `failed`, and refresh the balance with `getBalance`, at most once every 5 seconds.
6. When the socket closes, wait 2 seconds and connect again. The reconnect runs steps 3 and 4 once more, so a short outage is filled from history and the Set drops repeats.

`main.ts` (run: `CARBIUM_KEY=<YOUR_KEY> node main.ts <WALLET_ADDRESS>`)

```ts
// BI0005 · Wallet activity tracker
// https://carbium.sh/library/blockchainideas/wallet-activity-tracker
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { 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);
}
if (!process.argv[2]) {
  console.error("Usage: node main.ts <wallet address>");
  process.exit(1);
}
const wallet = address(process.argv[2]); // throws on a malformed address
const WS_URL = `${process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh"}/?api-key=${key}`;
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

const HISTORY = 5; // rows to show from getSignaturesForAddress on each connect
const seen = new Set<string>();
let lastBalanceAt = 0;

// kit turns the numbers in a history row's err into bigints (Custom: 7n), which plain JSON.stringify rejects
const status = (err: unknown) =>
  err === null ? "ok" : `failed ${JSON.stringify(err, (_k, v) => (typeof v === "bigint" ? Number(v) : v))}`;

async function backfill(): Promise<void> {
  try {
    const rows = await rpc.getSignaturesForAddress(wallet, { limit: HISTORY, commitment: "confirmed" }).send();
    for (const r of [...rows].reverse()) {
      if (seen.has(r.signature)) continue;
      seen.add(r.signature);
      const at = r.blockTime === null ? "unknown time" : new Date(Number(r.blockTime) * 1000).toISOString();
      console.log(`PAST ${at} ${r.signature} ${status(r.err)}`);
    }
  } catch (e) {
    console.error("getSignaturesForAddress failed:", e instanceof Error ? e.message : e);
  }
}

async function balance(): Promise<void> {
  if (Date.now() - lastBalanceAt < 5000) return;
  lastBalanceAt = Date.now();
  try {
    const { value } = await rpc.getBalance(wallet, { commitment: "confirmed" }).send();
    console.log(`  balance ${(Number(value) / 1e9).toFixed(4)} SOL`);
  } catch (e) {
    console.error("getBalance failed:", e instanceof Error ? e.message : e);
  }
}

function connect(): void {
  const ws = new WebSocket(WS_URL);
  ws.onopen = () => {
    ws.send(JSON.stringify({
      jsonrpc: "2.0", id: 1, method: "logsSubscribe",
      params: [{ mentions: [wallet] }, { commitment: "confirmed" }],
    }));
  };
  ws.onmessage = (ev) => {
    const msg = JSON.parse(String(ev.data));
    if (msg.id === 1) {
      if (msg.error) {
        console.log(`subscribe refused: ${msg.error.message}`);
      } else {
        console.log(`subscribed, id ${msg.result}`);
        void backfill().then(balance); // history starts once the stream is confirmed, so nothing falls between
      }
      return;
    }
    if (msg.method !== "logsNotification") return;
    const { signature, err } = msg.params.result.value as { signature: string; err: unknown };
    if (seen.has(signature)) return;
    seen.add(signature);
    console.log(`LIVE ${new Date().toISOString()} ${signature} ${status(err)}`);
    void balance();
  };
  ws.onclose = () => setTimeout(connect, 2000);
  ws.onerror = () => ws.close();
}

connect();
```

The wallet address is the only filter. logsSubscribe takes one address per subscription, so one tracker process watches one wallet. For several wallets, open one subscription each and share the Set, since a transaction between two watched wallets arrives once per subscription.

Kit's response transformer turns the numbers inside a history row's `err` into bigints, so `Custom: 7` arrives as `7n`. The code prints `err` through `JSON.stringify` with a replacer that turns a bigint back into a number, because plain `JSON.stringify` throws on a bigint at the first failed row.

> accountSubscribe stays silent for a plain SOL wallet on Carbium, which is why the tracker reads the logs that mention the address and then calls getBalance.

The history shows 5 rows because the screen only needs context. Raise the limit, or page back with `before`, for more, up to the 30 days the address index keeps.

## What it costs

Credits and cells both apply. [Credits](https://carbium.sh/docs#limits) meter RPC and WebSocket work. The subscription is billed in credits: a logs-mentions subscription opens at 25 credits, then costs 20 credits per MiB sent, and a refused one is free. Cells are the admission charge per call, and they set how many calls per second a plan lets through. getSignaturesForAddress costs 50 cells, and the tracker makes one such call per connect.

Credit use follows the notifications that mention the wallet. At 2 KiB per notification, a wallet with 100 transactions a day sends about 0.2 MiB, which is about 4 credits on top of the 25 to open. A very busy one at 10 transactions per second for an hour sends about 70 MiB, which is about 1,400 credits.

| Plan | Credits | History call rate | Busy hour, subscription only, as a share of credits |
|---|---|---|---|
| Free ($0) | 500K once, at sign-up | 0.24 req/s | about 0.3% of the grant |
| Dev ($20) | 10M per month | 1.2 req/s | about 0.014% of the month |
| Business ($250) | 50M per month | 100 req/s | about 0.003% of the month |
| Pro ($500) | 200M per month | 500 req/s | about 0.0007% of the month |

The busy-hour figures cover the subscription only. Balance reads come on top: on a busy wallet the 5-second spacing allows up to 720 an hour, plus one after each history call. Each is an ordinary [RPC call](https://carbium.sh/docs#rpc) and draws on the plan's call rate.

On Free, 0.24 req/s is one history call about every 4 seconds, which one call per connect never approaches unless the socket keeps dropping. Limits are per account, so other keys and tools on the account draw on the same budget. Free carries 5 sockets, and the tracker uses one.

## What to add next

- Several wallets: loop over a list of addresses, one subscription each, and print the wallet next to the signature.
- Row detail: call `getTransaction` (50 cells) on each new signature to show the fee payer, the programs involved and the balance change. On Free, sample them.
- An alert: post to a channel when a `failed` row or an outgoing transfer shows up. The same `err` check, counted per error, is in [Failed-mint monitor](https://carbium.sh/library/blockchainideas/failed-mint-monitor).
- Your own archive: write each row into `node:sqlite`. Carbium's history stops at 30 days, so a table you fill as rows arrive is the only way to keep more.
- Confirmation of a payment you send: `signatureSubscribe` sends one confirmation for a signature, then the subscription ends, which suits a single payment better than a wallet-wide stream.

## Where it ends

- History reaches back 30 days at most, from Carbium's own address index. An empty page past that is the index's age limit and says nothing about the wallet's first transaction.
- logsSubscribe takes one address per subscription, so one subscription watches one wallet.
- An incoming token transfer lists the token account and usually not the owner wallet, so the wallet's subscription can miss it. Watch the token account's address too, or read balances as in [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance).
- Live rows carry no block time. The tracker prints its own clock at arrival.
- A balance line follows the history, then a live row only when 5 seconds have passed since the last read. Live rows inside that gap get no new balance read, so after a burst the last line can stay stale until the next transaction.
- Only transactions that landed produce logs. One that was dropped, or whose blockhash expired, never appears.
- A reconnect backfills only the last 5 signatures. A longer outage needs a larger limit or paging.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The subscribe reply is an error, or the socket closes straight away. | Check `CARBIUM_KEY` and that the account is under its socket cap (Free carries 5). A refused subscription is free, so retrying costs nothing. |
| Only PAST rows print and then nothing. | The wallet is quiet. If `subscribed, id ...` printed, the stream works and the next transaction on the address will appear. Send a small amount from another wallet, or point the tracker at a busier address, to check. |
| getSignaturesForAddress returns an empty page for a wallet with older activity. | The address index keeps up to 30 days. An empty page past that is the index's age limit, so it says nothing about the wallet's first transaction. Keep your own archive from now on. |
| The history call answers 429. | Each connect makes one history call, so a 429 that repeats points to a socket closing in a loop. The close reason shows why. Limits are shared across the account's keys. |
| The same signature prints twice after a restart. | The Set lives in the process, so a restart forgets it and the history call prints the last 5 again. Store signatures in `node:sqlite` and skip the ones you have. |
| An incoming token transfer is missing. | The transaction lists the token account, so subscribe to that address too. |

## Questions

### Do I need my own node to track a wallet?

No. The WebSocket, the history call and the balance read all come from services.carbium.sh with one key.

### Why not use accountSubscribe on the wallet?

On Carbium it stays silent for a plain SOL wallet. The tracker subscribes to logs that mention the address and reads the balance with getBalance.

### How far back can the tracker look?

Up to 30 days, the reach of Carbium's address index. To keep more, write each row to a table as it arrives.

### Can I watch several wallets on the Free plan?

Within the caps, yes. Free carries 5 sockets, and subscription counts are capped per account by tier. Each wallet needs its own subscription, which opens at 25 credits.

### Does it show failed transactions?

Yes. The notification carries the result, and a failed row prints `failed` with the error object. A transaction that never landed produces no logs and does not appear.

## Related

- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [Failed-mint monitor](https://carbium.sh/library/blockchainideas/failed-mint-monitor) (Blockchain ideas, BI0001)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
