library / Blockchain ideas / BI0016
Whale transfer alerts
A logsSubscribe per watched wallet and one getTransaction per confirmed transaction turn large SOL moves in or out of those wallets into alert lines. You get the credit and call costs per plan, the limits, and a runnable main.ts.
Who uses it
Three groups want a whale alert. A community channel posts when a known large holder moves funds. A treasury or foundation team watches its own cold wallets and wants a line the moment anything leaves. A researcher keeps a short list of addresses and wants the amounts without opening an explorer for each one.
The list of addresses is yours: the code watches the addresses you pass and does not search for large holders. Good candidates are a treasury, an exchange hot wallet or an early holder. A hackathon team can point it at any public address, since every transaction on Solana is readable by anyone, and the alert threshold is one environment variable. Streaming and lookups come from services.carbium.sh under one key.
What it shows
Every confirmed transaction that mentions a watched wallet becomes one line, and the line says how much SOL that wallet gained or lost.
| Column | Meaning | Example |
|---|---|---|
| Tag | PAST for a transaction read from recent history at start, LIVE for one that arrived on the socket | LIVE |
| Level | WHALE when the move is at or over the threshold, otherwise small | WHALE |
| Move | in or out, then the wallet's SOL change | out 2500.00 SOL |
| Wallet | The watched address the move belongs to | the address you passed |
| Signature | The transaction id | the id you paste into an explorer |
The move is the wallet's own balance change: its lamports after the transaction minus its lamports before, read from the transaction's meta. That nets out everything the transaction did to the wallet, and the fee is in the move only when the watched wallet paid it as fee payer. For a move of hundreds of SOL the fee is rounding. The threshold defaults to 1000 SOL and WHALE_MIN_SOL=0 makes every line a WHALE line, which is a quick way to see the output on a quiet address.
All three calls, the subscription, the history page and the transaction lookup, name confirmed explicitly, so a line prints once the transaction is confirmed.
The build
The watcher is a single file with one dependency, @solana/kit, plus what Node 24 ships. Nothing in it signs or sends: there is no key pair. Run it as node main.ts <address> [address...]. If you want one wallet with a balance line, see Wallet activity tracker.
- Input: CARBIUM_KEY, the addresses as arguments and WHALE_MIN_SOL. If the key or every address is missing, a usage line prints and the process exits. Kit's address() rejects a malformed string before any request is made.
- RPC: one client is created at start and carries the key in the x-api-key header for every lookup.
- Socket: one WebSocket connects to wss://services.carbium.sh with ?api-key= in the URL. On open it sends a logsSubscribe per address with { mentions: [address] } and its own request id. A subscribe reply hands back a subscription id, and notifications name only that id, so a map recovers the address.
- Backfill: after subscribing, getSignaturesForAddress with a limit of 3 pulls each address's newest signatures, and those print tagged PAST. The per-address work sits in Promise.allSettled, so a failure on one address does not stop the rest.
- Filter: a logsNotification whose transaction failed, or whose wallet and signature pair is already in the seen set, is skipped. Everything else goes to getTransaction with jsonParsed encoding.
- Version: getTransaction carries maxSupportedTransactionVersion: 1. Mainnet has v1 transactions, and a value that is absent or 0 gets -32015 back for one, as described in Transaction version error -32015.
- Null results: a notification can beat the transaction to the ledger, and an address-index signature can sit below the validator's ledger floor, so the lookup can return null. The code asks up to four times, 500 ms apart, then prints that the transaction was not readable.
- Reconnect: when the socket closes, a new one opens after 2 seconds. It subscribes and backfills again, and the seen set swallows what was already printed.
// BI0016 · Whale transfer alerts// https://carbium.sh/library/blockchainideas/whale-transfer-alerts// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type Signature } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key || process.argv.length < 3) { console.error("Usage: CARBIUM_KEY=<key> [WHALE_MIN_SOL=1000] node main.ts <address> [address...]"); process.exit(1);}const watched = process.argv.slice(2).map((a) => address(a)); // throws on a malformed addressconst MIN_SOL = Number(process.env.WHALE_MIN_SOL ?? 1000);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 seen = new Set<string>();const subs = new Map<number, string>(); // subscription id -> watched addressasync function inspect(tag: string, wallet: string, signature: Signature): Promise<void> { for (let attempt = 0; attempt < 4; attempt++) { try { const tx = await rpc .getTransaction(signature, { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }) .send(); if (tx === null) { await new Promise((r) => setTimeout(r, 500)); continue; } const i = tx.transaction.message.accountKeys.findIndex((k) => k.pubkey === wallet); const meta = tx.meta; if (i < 0 || !meta) { console.log(`${tag} ${signature} wallet not in the account keys`); return; } const sol = (Number(meta.postBalances[i]) - Number(meta.preBalances[i])) / 1e9; const level = Math.abs(sol) >= MIN_SOL ? "WHALE" : "small"; console.log(`${tag} ${level} ${sol >= 0 ? "in" : "out"} ${Math.abs(sol).toFixed(2)} SOL ${wallet} ${signature}`); return; } catch (e) { console.error(`getTransaction ${signature} failed:`, e instanceof Error ? e.message : e); return; } } console.log(`${tag} ${signature} not readable (null)`);}async function history(): Promise<void> { const results = await Promise.allSettled( watched.map(async (w) => { const rows = await rpc.getSignaturesForAddress(w, { limit: 3, commitment: "confirmed" }).send(); for (const r of [...rows].reverse()) { if (r.err !== null || seen.has(`${w}:${r.signature}`)) continue; seen.add(`${w}:${r.signature}`); await inspect("PAST", w, r.signature); } }), ); results.forEach((r, i) => { if (r.status === "rejected") console.error(`history for ${watched[i]} failed:`, r.reason instanceof Error ? r.reason.message : r.reason); });}function connect(): void { const ws = new WebSocket(WS_URL); ws.onopen = () => { subs.clear(); console.log(`watching ${watched.length} address(es), alert at ${MIN_SOL} SOL`); watched.forEach((w, i) => { ws.send(JSON.stringify({ jsonrpc: "2.0", id: i + 1, method: "logsSubscribe", params: [{ mentions: [w] }, { commitment: "confirmed" }] })); }); void history(); }; ws.onmessage = (ev) => { const msg = JSON.parse(String(ev.data)); if (typeof msg.id === "number") { if (msg.error) console.log(`subscribe refused for ${watched[msg.id - 1]}: ${msg.error.message}`); else subs.set(msg.result, watched[msg.id - 1]); return; } if (msg.method !== "logsNotification") return; const wallet = subs.get(msg.params.subscription); const { signature, err } = msg.params.result.value; if (!wallet || err !== null || seen.has(`${wallet}:${signature}`)) return; seen.add(`${wallet}:${signature}`); void inspect("LIVE", wallet, signature); }; ws.onclose = () => setTimeout(connect, 2000); ws.onerror = () => ws.close();}connect();
run: CARBIUM_KEY=<YOUR_KEY> WHALE_MIN_SOL=1000 node main.ts <ADDRESS> [<ADDRESS> ...]
The wallet's index in the transaction's account keys is also its index in the pre and post balance arrays, so the move comes out of the transaction without a separate getBalance call. If the wallet is missing from that list, the code prints that and moves on.
logsSubscribe takes one address per subscription, so ten wallets mean ten subscriptions, each with its own opening charge. The seen set is keyed by wallet and signature, so a transfer between two watched wallets prints once for each, which is right, since each wallet moved.
What it costs
Two meters apply. Credits meter RPC and WebSocket work: a logs-mentions subscription opens at 25 credits and then costs 20 credits per MiB sent, and a refused subscription costs nothing. Cells are the admission charge per call and set how many calls per second a plan lets through. Both getSignaturesForAddress and getTransaction cost 50 cells.
The call that sets the ceiling is getTransaction, because each notification triggers one.
| Plan | Credits | getTransaction rate | One lookup every |
|---|---|---|---|
| Free ($0) | 500K once, at sign-up | 0.24 req/s | about 4 seconds |
| Dev ($20) | 10M per month | 1.2 req/s | about 0.8 seconds |
| Business ($250) | 50M per month | 5 req/s | 0.2 seconds |
| Pro ($500) | 200M per month | 25 req/s | 0.04 seconds |
A class absorbs bursts up to 1,024 cells, which is about 20 lookups at once, or one second of its rate if that is larger. The start-up history costs 200 cells per address, one page and three lookups. Pages and lookups sit in different rate classes with separate buckets, so five addresses spend 250 cells on pages and 750 on lookups, each inside its own class's 1,024-cell burst on any plan, and every null retry adds 50 cells a try. After that the plan's rate is the limit: a watched wallet that sends more notifications per second than your lookup rate will lose lines. An exchange hot wallet can do that on Free or Dev. Raising the threshold will not help, since the filter runs after the lookup. To thin the load, watch quieter wallets or sample the notifications.
Limits are per account, so other keys and tools on the account draw on the same budget. Free carries 5 sockets, and the watcher uses one for any number of addresses. The plan also caps subscriptions per account, so a long list needs a plan to match.
What to add next
- Delivery: post each WHALE line to a chat channel or a webhook of your own. The alert is one if on the level.
- A log: write each line into node:sqlite with the wallet, the signature and the move. Carbium's history stops at 30 days, so a table you fill as lines arrive is the only way to keep more.
- Names: map addresses to labels such as treasury or hot wallet 2 in a small object and print the label next to the address.
- Token moves: read a wallet's token accounts with getTokenAccountsByOwner and subscribe to the ones that matter.
- Sampling: on a busy wallet, call getTransaction for one notification in N and count the rest, so the lookup rate stays under the plan.
Where it ends
- It reports native SOL only. A token transfer to an existing token account lists the token accounts and the sender's authority, never the receiving wallet, so a subscription on a wallet address misses incoming tokens and the code reads no token amounts.
- It watches the addresses you give it. Nothing in it finds large holders, and the list needs your upkeep.
- The move is a net balance change. A transaction that sends SOL out of a wallet and back in the same transaction shows a small number, and one that opens or closes accounts folds the rent into the move.
- History reaches back 30 days at most, from Carbium's own address index, and the start-up page shows only the newest 3 transactions per address.
- If notifications outrun the lookup rate, a lookup that fails is printed to stderr and is not retried, so that alert is lost. Only a null result is retried.
- The set of seen signatures lives in the process. A restart forgets it, and the start-up history prints again.
- Only transactions that landed produce logs. One that was dropped never appears.
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 and subscription caps. A refused subscription costs nothing, so a retry is free. |
| Only PAST lines print and then nothing. | The wallets are quiet. If no subscribe refused line appeared, the stream works and the next transaction on the address will print. Set WHALE_MIN_SOL=0 to see every move, or watch a busier address. |
| Lookups answer 429 during a busy stretch. | The wallet sends more notifications per second than your plan's getTransaction rate. Sample the notifications, watch fewer or quieter wallets, or move to a plan with a higher rate. Read the retry-after hint before trying again. |
| A line says the transaction was not readable. | The lookup stayed null through four tries. A signature from the address index can sit below the validator's ledger, and an alert for a fresh transaction can be asked for too early. Try the signature again in a few seconds, or in an explorer. |
| getTransaction answers -32015. | Send maxSupportedTransactionVersion: 1 with the call. The value absent or 0 fails for a v1 transaction. |
| An incoming token transfer never alerts. | The transaction lists the token account and not the owner wallet. Subscribe to the token account's address too, and read its amount with getTokenAccountBalance. |
Questions
What counts as a whale?
Whatever you set. The watcher alerts on any watched wallet whose SOL balance changes by at least WHALE_MIN_SOL in one transaction, and the default is 1000.
Do I need my own node?
No. The WebSocket, the history page and the lookups all come from services.carbium.sh with one key.
Can it alert on token transfers?
Not as written. It reads SOL balances only. For tokens, watch the token account addresses and read the amounts from the token balances in the transaction.