Address poisoning dust detector
A Node script reads a wallet's newest transactions, finds tiny SOL deposits from addresses the wallet never used, and flags senders whose first and last characters copy one it did. You get a list to hide or block, and the limits of the check.
How the dust gets there
Address poisoning is a copy-paste trap. After a wallet pays an address, an attacker sends it a tiny transfer from a different address that starts and ends with the same characters as the one it just paid. Wallet histories shorten addresses to their first and last few characters, so the copy sits in the list next to the real one. If the owner later copies a recipient from history, the next payment goes to the attacker.
That explains why the dust shows up after a swap or an SPL transfer. Nothing in your transaction created it. Transactions are public once they land, the counterparty's address is in them, and the attacker grinds a keypair whose ends match that address and sends the dust. The sender is an address you never used, so it reads as unknown.
Small unknown deposits also come from harmless sources, such as an exchange returning a remainder or an unsolicited airdrop. The detector does not try to prove intent. It sorts each small deposit by whether the sender is an address your wallet has dealt with and whether it looks like one.
What the detector checks
- Read the wallet's newest signatures and fetch each successful transaction with parsed accounts and balances.
- Collect every address that appears in a transaction the wallet signed. That set is the wallet's known counterparties.
- For each transaction the wallet did not sign, take the wallet's SOL balance change from the balances before and after.
- Keep deposits of at most 1,000,000 lamports (0.001 SOL) and take the first signer as the sender.
- Label the sender: known counterparty, lookalike of a known address, or unknown sender.
| Label | Meaning | What to do |
|---|---|---|
| Lookalike | Different address, same first 4 and last 4 characters as a known one | Hide it in history and warn in the send flow |
| Unknown sender | Never seen in the window, no lookalike | Review it, do not block on it alone |
| Known counterparty | Address the wallet has signed with | Normal activity, the script skips it |
The reads and their cost
Two methods do the work. getSignaturesForAddress lists the newest signatures that mention the wallet, and getTransaction returns one transaction with its balances before and after. Each costs 50 cells, so a run over 20 signatures spends 21 reads, 1,050 cells.
The script reads one transaction after another and stops fetching after 20 seconds, so a plan with a low getTransaction rate prints what it reached. The loop catches a 429 per call and counts it.
Every call reads at confirmed commitment.
getTransaction takes maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and a call with the value absent or 0 answers -32015 for one of them, uncharged. The loop catches each call, so without the field a v1 swap counts as failed and drops out of the check. Transaction version error -32015 covers the error in full.
A script in one file
Run it with one wallet address. With none, it reads the newest signatures of the System Program and takes the first account whose balance rose in a transaction it did not sign, so the run always has a wallet with fresh activity. It prints one line per flagged deposit with the first 12 characters of the signature, the sender, the amount and the label, then a summary of how many transactions it read, how many were incoming and how many were flagged. Deposits from known counterparties are skipped before the count. It reads CARBIUM_KEY and exits with a message when it is unset, and it takes an optional CARBIUM_RPC_URL. It signs and sends nothing.
// UC0030 · Address poisoning dust detector// https://carbium.sh/library/usecase/address-poisoning-dust-detector// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: flags small SOL deposits into a wallet and checks each sender for a lookalike of an address the wallet has used.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); }const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const DUST = 1_000_000n; // lamports, 0.001 SOLconst rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));type Key = { pubkey: string; signer: boolean };type Tx = { transaction: { message: { accountKeys: Key[] } }; meta: { preBalances: (number | bigint)[]; postBalances: (number | bigint)[] } | null;};const fetchTx = async (sig: string) => (await rpc .getTransaction(sig as Parameters<typeof rpc.getTransaction>[0], { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }) .send()) as unknown as Tx | null;// No argument: take an account that just received lamports in a recent System Program transaction.async function recentRecipient(): Promise<string> { const recent = await rpc.getSignaturesForAddress(address("11111111111111111111111111111111"), { limit: 5, commitment: "confirmed" }).send(); for (const s of recent) { if (s.err !== null) continue; try { const tx = await fetchTx(s.signature); const m = tx?.meta; if (!tx || !m) continue; const keys = tx.transaction.message.accountKeys; const i = keys.findIndex((k, j) => !k.signer && BigInt(m.postBalances[j]) > BigInt(m.preBalances[j])); if (i >= 0) return keys[i].pubkey; } catch (e) { console.error("getTransaction failed:", (e as Error).message); } } console.error("No recent recipient found. Pass a wallet address."); process.exit(1);}const wallet = process.argv[2] ?? (await recentRecipient());const sigs = (await rpc.getSignaturesForAddress(address(wallet), { limit: 20, commitment: "confirmed" }).send()) .filter((s) => s.err === null);const txs: { sig: string; tx: Tx }[] = [];const started = Date.now();let failed = 0, missing = 0;for (const s of sigs) { if (Date.now() - started > 20_000) break; try { const tx = await fetchTx(s.signature); if (tx?.meta) txs.push({ sig: s.signature, tx }); else missing++; // null: older than the ledger floor } catch (e) { if (failed++ === 0) console.error("getTransaction failed:", (e as Error).message); }}const signs = (t: Tx, who: string) => t.transaction.message.accountKeys.some((k) => k.signer && k.pubkey === who);// Known counterparties: every address in a transaction the wallet signed.const known = new Set<string>();for (const { tx } of txs) if (signs(tx, wallet)) tx.transaction.message.accountKeys.forEach((k) => known.add(k.pubkey));known.delete(wallet);// A lookalike shares the first 4 and last 4 characters with a known address and is a different address.const twinOf = (a: string) => [...known].find((k) => k !== a && k.slice(0, 4) === a.slice(0, 4) && k.slice(-4) === a.slice(-4));let incoming = 0, flagged = 0;for (const { sig, tx } of txs) { const keys = tx.transaction.message.accountKeys; const i = keys.findIndex((k) => k.pubkey === wallet); if (i < 0 || signs(tx, wallet)) continue; incoming++; const m = tx.meta!; const delta = BigInt(m.postBalances[i]) - BigInt(m.preBalances[i]); if (delta <= 0n || delta > DUST) continue; const sender = keys.find((k) => k.signer)?.pubkey ?? "unknown"; if (known.has(sender)) continue; flagged++; const twin = twinOf(sender); console.log(`${sig.slice(0, 12)} ${sender} ${delta} lamports ${twin ? `LOOKALIKE of ${twin}` : "unknown sender"}`);}console.log(`${wallet}: ${txs.length} transactions read (${failed} failed, ${missing} null), ${incoming} incoming, ${flagged} flagged`);
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts <wallet>
Balances arrive as integers, so the threshold compare uses BigInt and has no float in it. The 1,000,000 lamport limit is a constant at the top. Move it to suit the wallet: an address that gets many small legitimate deposits wants a lower limit and a longer review list.
Acting on a flag
- Hide lookalike rows in the history view or mark them with a warning, and keep the original row for audit.
- Show the whole address in a send flow and ask for a second confirmation the first time an address is paid. Comparing the first and last characters is the check the attacker has already beaten.
- Build the recipient list from an address book the user filled, never from history.
- Do not reply to the sender. A return transfer only adds another row for the lookalike to the history.
Catching it as it lands
A scheduled read finds poison after the fact. To flag it on arrival, open a logsSubscribe mentions filter on the wallet over the WebSocket. accountSubscribe sends nothing for a plain SOL wallet, so it cannot do this job. A logs-mentions subscription opens at 25 credits and then costs 20 credits per MiB sent, and your plan caps sockets per account, with 5 on Free. On each notification take the signature and run the one-transaction version of the same check.
To push address activity to your own server without holding a socket, see Address transaction webhooks.
Where it ends
- History reaches back 30 days at most. getSignaturesForAddress pages come from Carbium's own address index, and an empty page past that is the index's age limit, so the wallet may have older transactions. Its pages reach below the validator's ledger floor, so getTransaction can answer null for an older signature it lists. The script counts those.
- SOL dust only. A tiny or zero-amount SPL transfer lists the token accounts and the sender's authority and never the receiving wallet, so the wallet's own signature list does not hold it. Finding those means listing the wallet's token accounts with getTokenAccountsByOwner and reading signatures for each, which this script does not do.
- The known set comes from the window you read. A counterparty paid before the window is unknown to the script, and a dust sender copying it shows as unknown sender. Widen the window to learn more.
- A lookalike means the same first 4 and last 4 characters. An attacker who matched fewer characters passes as an unknown sender.
- The sender is the first signer. A transaction with a relayer or several signers names the first one.
- The script reports and decides nothing. It cannot stop a user from copying the wrong address.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| getTransaction answers -32015 for a swap in the window. | Pass maxSupportedTransactionVersion: 1 in the config. The error is uncharged, so a missing value costs time and no cells. |
| getTransaction returns null for a signature the page listed. | The address index reaches below the validator's ledger floor. Count the null, skip it and judge on the newer signatures. |
| The first calls print 429. | Keep the calls in sequence on one client, and shrink the window on a plan with a low getTransaction rate. The script counts each one as failed and judges the rest. |
| Every exchange refund is labeled unknown sender. | Treat unknown sender as a review list and act automatically only on lookalike. Lower the lamport limit if the wallet gets real small deposits. |
| A dust sender that copies a known address shows as unknown sender. | The paid address sat outside the window. Read more signatures, or seed the known set from the user's address book. |
Questions
Did my swap cause the dust?
No. The swap made your address and its counterparties visible. An attacker watching the chain reacts to them with a tiny transfer from a lookalike address.
Is the dust dangerous to hold?
A few lamports do nothing on their own. The danger is copying the sender, or a counterparty taken from history, into a send form. Leave the dust alone and check full addresses.
Why read balance changes and skip the transfer instructions?
The balance arrays give the wallet's net change in one field, whichever program moved the lamports. A deposit made inside another program's call is covered too.
How do I catch zero-amount SPL poison?
This script cannot, because the transfer never lists the receiving wallet. List the wallet's token accounts with getTokenAccountsByOwner, read the signatures of each, and run the same lookalike check on the sender authority.