---
id: UC0042
title: "Deposit AML screening"
url: https://carbium.sh/library/usecase/deposit-aml-screening
collection: Use cases
category: Compliance, risk and monitoring
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Deposit AML screening

Check each Solana deposit against your own list of blocked addresses before you credit it. A Node script reads the senders from the transaction, looks one hop back at who funded them, and prints a verdict.

## What a deposit screen reads

An AML check on a deposit asks two questions about the money: who sent it, and where that sender got its funds. Solana keeps both answers in public transaction history. The job is to read them out and compare them with a list of addresses your compliance team already treats as blocked or high risk.

Reading the sender takes care. A token transfer lists the token accounts and the sender's authority, and it never lists the receiving wallet. The transaction's token balances before and after carry an `owner` field for each token account, so the script takes senders and receivers from the owners whose balance fell or rose. A wallet can own more than one token account for one mint, so the balances are keyed by account index and mint together. When a transaction moves no tokens, the script falls back to the SOL balance change of each account key.

One hop is as deep as the script goes. For each sender it lists the latest signatures, reads the transactions that paid funds into that sender, and checks the wallets that paid it. A sender that is absent from your list but was funded by a listed wallet gets the verdict `review`.

> The list is yours. The script reads one address per line from the file named in `BLOCKLIST`, skips blank lines and lines that start with `#`, and compares exact addresses. It ships no addresses, because which wallets to block is a policy decision that someone in your company owns.

## The screen in one file

Pass a deposit address as the argument, or pass nothing. With an address, the script lists its latest 10 signatures and takes the first successful transaction that raised its balance. With no argument it does the same on the USDC mint, whose newest transactions include transfers and swaps, and screens the first owner whose token balance rose in one of them. `CARBIUM_KEY` is required and `BLOCKLIST` is the optional path of your list. Three constants set the reach: `SCAN` signatures searched for the deposit (10), `SENDERS` screened (3) and `HOP` signatures read per sender (3). RPC goes through `@solana/kit` to `CARBIUM_RPC_URL`, which is `https://services.carbium.sh` when unset, with the key sent in the [x-api-key header](https://carbium.sh/docs#auth).

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY BLOCKLIST=blocklist.txt node main.ts [<deposit-address>]`)

```ts
// UC0042 · Deposit AML screening
// https://carbium.sh/library/usecase/deposit-aml-screening
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only: screens one deposit against your own address list. It reads who sent it, then who funded each sender one hop back.
import { readFileSync } from "node:fs";
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, signature } 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 rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({
  url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key } }));
const LEVEL = "finalized" as const;
const SCAN = 10, SENDERS = 3, HOP = 3; // signatures searched for the deposit, senders screened, signatures read per sender
const USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
const target = process.argv[2];
if (target) address(target); // throws on a malformed address
const blocked = new Set(process.env.BLOCKLIST
  ? readFileSync(process.env.BLOCKLIST, "utf8").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#")) : []);

type Bal = { accountIndex: number; mint: string; owner?: string; uiTokenAmount: { amount: string } };
type Tx = { transaction: { message: { accountKeys: { pubkey: string }[] } };
  meta: { err: unknown; preBalances: (number | bigint)[]; postBalances: (number | bigint)[]; preTokenBalances?: Bal[]; postTokenBalances?: Bal[] } };
let failed = 0;
const tryit = async <T>(what: string, f: () => Promise<T>): Promise<T | undefined> => {
  try { return await f(); } catch (e) { failed++; console.error(`${what} failed: ${e instanceof Error ? e.message : e}`); }
  return undefined;
};
const fetchTx = async (sig: string): Promise<Tx> => {
  // version 1, so a v1 transaction reads instead of answering -32015
  const tx = (await rpc.getTransaction(signature(sig), { encoding: "jsonParsed", maxSupportedTransactionVersion: 1, commitment: LEVEL }).send()) as unknown as (Tx | null);
  if (!tx?.meta) throw new Error(`transaction ${sig} not served`);
  return tx;
};

// Owners whose balance fell (down) or rose (up): token balances when the transaction has any, else SOL.
function moves(tx: Tx) {
  const m = tx.meta, down = new Set<string>(), up = new Set<string>();
  const amounts = (l?: Bal[]) => new Map((l ?? []).map((b): [string, bigint] => [`${b.accountIndex}:${b.mint}`, BigInt(b.uiTokenAmount.amount)]));
  const tokens = [...(m.preTokenBalances ?? []), ...(m.postTokenBalances ?? [])];
  if (tokens.length) {
    const pre = amounts(m.preTokenBalances), post = amounts(m.postTokenBalances);
    for (const b of tokens) {
      const id = `${b.accountIndex}:${b.mint}`, d = (post.get(id) ?? 0n) - (pre.get(id) ?? 0n);
      if (b.owner && d < 0n) down.add(b.owner);
      if (b.owner && d > 0n) up.add(b.owner);
    }
  } else {
    tx.transaction.message.accountKeys.forEach((k, i) => {
      const d = BigInt(m.postBalances[i]!) - BigInt(m.preBalances[i]!);
      if (d < 0n) down.add(k.pubkey); else if (d > 0n) up.add(k.pubkey);
    });
  }
  return { down: [...down], up: [...up] };
}

async function main() {
  const base = target ?? USDC;
  const page = await tryit("deposit signatures", () => rpc.getSignaturesForAddress(address(base), { limit: SCAN, commitment: LEVEL }).send());
  let found: { sig: string; dep: string; down: string[] } | undefined;
  for (const s of page ?? []) {
    if (found) break;
    if (s.err) continue;
    const tx = await tryit("deposit transaction", () => fetchTx(s.signature));
    if (!tx || tx.meta.err) continue;
    const m = moves(tx), dep = target ? m.up.find((u) => u === target) : m.up[0];
    if (dep) found = { sig: s.signature, dep, down: m.down.filter((d) => d !== dep) };
  }
  if (!found) {
    if (!page) { console.error("the deposit signature list failed, so nothing was screened"); process.exit(1); }
    return console.log(`no incoming transfer to ${base} in its latest ${SCAN} signatures`);
  }
  const senders = [];
  for (const sender of found.down.slice(0, SENDERS)) {
    const funders = new Set<string>();
    const sigs = await tryit(`history of ${sender}`, () => rpc.getSignaturesForAddress(address(sender), { limit: HOP, commitment: LEVEL }).send());
    for (const s of sigs ?? []) {
      const tx = s.err ? undefined : await tryit("funding transaction", () => fetchTx(s.signature));
      if (!tx || tx.meta.err) continue;
      const m = moves(tx);
      if (m.up.includes(sender)) m.down.filter((d) => blocked.has(d)).forEach((d) => funders.add(d));
    }
    senders.push({ sender, direct: blocked.has(sender), viaHop: [...funders], recent: sigs?.length ?? null });
  }
  const verdict = senders.some((s) => s.direct) ? "hold" : senders.some((s) => s.viaHop.length) ? "review" : failed ? "incomplete" : "no match";
  console.log(JSON.stringify({ deposit: found.dep, sig: found.sig, listed: blocked.size, senders, verdict }, null, 1));
}
main().catch((e) => { console.error(e instanceof Error ? e.message : e); process.exit(1); });
```

`moves` decides who sent and who received. `fetchTx` reads with `jsonParsed` encoding and sets `maxSupportedTransactionVersion` to 1, because a [version 1 transaction](https://carbium.sh/docs#rpc) answers -32015 when the setting is absent or 0. A signature that lists but reads back null counts as a failed read. Every call names `finalized`, because a screen releases or holds money and kit would otherwise fill in `confirmed`.

The output is one JSON object: the deposit, its signature, how many addresses your list holds, one entry per sender with `direct`, `viaHop` and `recent`, and a `verdict`. `hold` means a sender is on your list. `review` means a wallet that funded a sender is on it. `incomplete` means no match turned up but at least one read failed, so the screen proves nothing yet. `no match` means every read succeeded and nothing matched. Each failed call also prints one line on stderr that names it.

`recent` counts the signatures returned for a sender, up to `HOP`. A sender that returns fewer than `HOP` has little history in the last 30 days. A fresh wallet funded once by another wallet is the shape that makes the hop check worth running.

## When to run it

Run the screen between the deposit landing and the credit. [Exchange deposit alerts](https://carbium.sh/library/usecase/exchange-deposit-alerts) shows the feed that finds a deposit and the ledger write that credits it. The screen goes before that write, and its verdict decides whether the credit posts, waits in a review queue or is held. [Multi-address deposit monitor](https://carbium.sh/library/blockchainideas/multi-address-deposit-monitor) covers watching many addresses at once.

If your feed already hands you the transaction signature, skip the search loop: call `fetchTx` on it once and keep `moves` and the sender reads. That removes up to 9 of the 10 transaction reads in the search.

Lists change after a deposit was credited. Store each deposit's senders and funders in your own table, and run them against every new version of the list as a batch job. That job needs no chain calls.

## What a screen costs

Two calls carry the work, and both [cost 50 cells](https://carbium.sh/docs#rpc).

| Call | Used for | Cells | Free req/s | Dev req/s | Business req/s | Pro req/s |
|---|---|---|---|---|---|---|
| getSignaturesForAddress | One for the deposit address, one per sender | 50 | 0.24 | 1.2 | 100 | 500 |
| getTransaction | Finding the deposit and reading each sender's funders | 50 | 0.24 | 1.2 | 5 | 25 |

With the defaults a screen makes at most 23 calls: one signature list for the deposit address, up to 10 transaction reads while it looks for the transfer, and for each of 3 senders one signature list and up to 3 funding reads. The two methods sit in separate rate classes, so each is measured on its own. A worst-case screen puts 19 reads, 950 cells, on `getTransaction` and 4 lists, 200 cells, on `getSignaturesForAddress`, and each stays inside the [1,024 cells a class absorbs as a burst](https://carbium.sh/docs#limits). When the first transaction is the deposit, a screen makes 14 calls and 700 cells.

The slower row sets the sustained pace, and that is `getTransaction`, with 10 reads in a typical screen. At the Dev rate of 1.2 req/s that is about 7 screens a minute, at Business 5 req/s about 30, and at Pro 25 req/s about 150. Free at 0.24 req/s fits an occasional screen. [Keys on one account share one budget](https://carbium.sh/docs#limits), so a second key adds no capacity.

## Where it ends

- No risk intelligence. The script matches exact addresses against your file. A risk score, a cluster of related wallets or an exposure percentage comes from data you license or build.
- Depth: one hop, 3 senders and 3 funding reads for each. A funding chain of two or more steps, and anything a sender did before its latest 3 signatures, goes unread.
- History: `getSignaturesForAddress` lists up to 30 days from Carbium's own address index, so a sender funded two months ago shows nothing. Its pages reach below the validator's ledger floor, so a listed signature can read back null, and the script counts that as a failed read.
- Intermediaries: a swap lists the pool as a sender, and an exchange hot wallet funds thousands of wallets. A list that contains such addresses flags nearly everything one hop away, so put on it the addresses you intend to act on.
- SOL fallback: when a transaction moves no tokens, the fee payer and every account whose lamports fell count as senders.
- Obligations such as reporting, the travel rule and case handling belong to your compliance process. The script reads and prints, and it signs and sends nothing.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The verdict is `incomplete` on every run. | At least one read failed, and stderr names which. A 429 means the plan's rate for that call ran out: lower `SENDERS` or `HOP`, spread the screens out or move up a plan. A null read means the signature sits below what the node serves, and a second run will not change it. |
| The script prints that it found no incoming transfer to the address in its latest 10 signatures. | The deposit is older than the search window, or the address only sent funds lately. Raise `SCAN`, or pass the signature you have to `fetchTx` and skip the search. |
| A liquidity pool or an exchange route shows up as a sender. | The script reports every owner whose balance fell. Add the known pools and routers to a skip set in your code before the list check, so they never reach `direct` or `viaHop`. |
| A deposit you know arrived is reported as not found. | You passed a token account address. The script matches the owner wallet that the token balances record, so pass the wallet that owns the account. |
| An address on the list never matches. | Matching is exact and base58 is case sensitive. The script trims whitespace and line endings, so check that the address was copied whole and that the line does not start with `#`. |

## Questions

### Does the script come with a list of bad addresses?

No. You supply the file, and `listed` in the output shows how many addresses it loaded, so an empty or missing file is visible at once. Its source is your compliance team or a list vendor.

### Can it screen a withdrawal before you send it?

Skip the deposit search and check the destination itself against the list. Then run the existing per-sender funding loop with the destination in place of a sender, since that loop already reads who paid an address.

### Why read transactions and not the token account balance?

A balance gives an amount and nothing about its origin. The transaction names the owners whose balances fell, and that is the sender you screen.

### Why only one hop?

Every hop multiplies the reads: with 3 senders and 3 funders each, a second hop adds up to 9 more signature lists and 27 more transaction reads. Deeper tracing fits a batch job on stored data.

## Related

- [Exchange deposit alerts](https://carbium.sh/library/usecase/exchange-deposit-alerts) (Use cases, UC0006)
- [Multi-address deposit monitor](https://carbium.sh/library/blockchainideas/multi-address-deposit-monitor) (Blockchain ideas, BI0006)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
