services
Get a key

library / Use cases / Stablecoin treasury and B2B settlement / UC0152

Duplicate payment detector

A signed transaction lands once, but a rebuilt copy has a new signature and can land beside the first. Read recent transfers on a mint, then flag repeated payments in one slot for review, with a Node script.

By Carbium · Stablecoin treasury and B2B settlement · UC0152 · updated 2026-11-23

01

One signed transaction lands once

A Solana transaction is identified by its signature, and that signature covers the message, including the recent blockhash it was built on. Send the same signed bytes twice and the second copy is rejected with AlreadyProcessed, so the transfer runs once. That holds while the blockhash is still valid. After the blockhash expires, the signed bytes cannot land at all.

CaseWhat the chain does
Same signed bytes sent twiceOne copy lands. The other is rejected as already processed.
Same transfer rebuilt with a new blockhashTwo signatures. Both can land, and both move the funds.
Signed bytes sent after the blockhash expiredNothing lands. Build and sign again.

For the question as asked, the answer is no for identical bytes and yes for a new transaction. The duplicate that costs money is usually the rebuilt kind. A checkout that times out builds a fresh transaction, and the wallet signs it again. The chain accepts both, so the check has to live in your own payment records.

02

Two payments that look the same

Both signatures are valid, both can sit in one slot, and the runtime has no view of which payment the customer meant. A wallet that shows a timeout may still have landed the first copy, which is how a customer ends up paying twice. A detector therefore compares what the transactions did. It groups each transfer leg by slot and reports any slot where two different signatures moved the same amount from the same source to the same destination under the same mint.

A flag is a review item, and it proves nothing alone. A payroll run that pays one wallet twice on purpose would flag the same way. Pull the flagged signatures into your payment records, match them to orders or invoices, and decide there. For the order side, memo payment lookup shows how to tie a transfer to one order, and deposit matching covers the database join.

03

Read the transfers and the slot

The detector makes two kinds of call. getSignaturesForAddress lists the newest signatures for the mint, at 50 cells a call. getTransaction then reads each transaction, also at 50 cells. Both go to the RPC endpoint with the key in the x-api-key header, as the code sets it.

Both reads pass confirmed commitment in the code, so the detector groups slots at that level and does not depend on a default. The transaction read uses jsonParsed encoding, so transfer instructions arrive with their source, destination, mint and amount already named. It also sets maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and without that setting getTransaction answers -32015 for one.

  • Keep only signatures with no error. A failed transaction moved nothing, so it cannot be a second payment.
  • Group by slot and by leg: source, destination, mint and amount. A missing mint means a native SOL transfer.
  • Read the newest transactions only. The address index keeps up to 30 days, so this endpoint cannot reach further back for a check.

With the default of 8 transactions, one run costs 450 cells: 50 for the listing and 50 for each read. That sits inside the 1,024-cell burst a rate class absorbs, so one run fits the burst. The limits page sets the per-account budget that every key on the account shares.

04

A detector in one file

The script takes an address as its argument and defaults to the USDC mint, a busy mint with transfers in every recent slot. DUP_LIMIT sets how many transactions it reads, and it defaults to 8. The key comes from CARBIUM_KEY, and the endpoint from CARBIUM_RPC_URL with the public default. The script sends only reads, signs nothing and writes no file.

main.ts
// UC0152 · Duplicate payment detector// https://carbium.sh/library/usecase/duplicate-payment-detector// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only check: flags slots where two signatures move the same transfer leg.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";const key = process.env.CARBIUM_KEY ?? "";if (!key) {  console.error("CARBIUM_KEY is not set. Export your Carbium key and run again.");  process.exit(1);}const target = process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";const sampleSize = Number(process.env.DUP_LIMIT ?? "8");const rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);type Ix = { parsed?: { type?: string; info?: Record<string, unknown> } };type Parsed = { slot: bigint | number; transaction: { message: { instructions: Ix[] } } };const LEG_TYPES = new Set(["transfer", "transferChecked"]);// One string per transfer leg: source, destination, mint and amount.function legsOf(tx: Parsed): string[] {  return tx.transaction.message.instructions.flatMap((ix) => {    const p = ix.parsed;    if (!p?.type || !LEG_TYPES.has(p.type)) return [];    const info = p.info ?? {};    const amount = (info.tokenAmount as { amount?: string } | undefined)?.amount ?? info.amount ?? info.lamports;    return [[info.source, info.destination, info.mint ?? "SOL", String(amount)].join("|")];  });}async function run(): Promise<void> {  const rows = await rpc.getSignaturesForAddress(address(target), { limit: 30, commitment: "confirmed" }).send();  const recent = rows.filter((r) => r.err === null).slice(0, sampleSize);  const cfg = { encoding: "jsonParsed", maxSupportedTransactionVersion: 1, commitment: "confirmed" } as const;  const outcomes = await Promise.allSettled(recent.map((r) => rpc.getTransaction(r.signature, cfg).send()));  const legSigs = new Map<string, Set<string>>();  let read = 0, nulls = 0, failed = 0;  for (let i = 0; i < outcomes.length; i++) {    const outcome = outcomes[i]!;    const sig = recent[i]!.signature;    if (outcome.status === "rejected") {      failed += 1;      const why = outcome.reason instanceof Error ? outcome.reason.message : String(outcome.reason);      console.error(`read failed for ${sig.slice(0, 8)}: ${why}`);      continue;    }    const tx = outcome.value as unknown as Parsed | null;    if (tx === null) { nulls += 1; continue; }    read += 1;    for (const leg of legsOf(tx)) {      const slotLeg = `${String(tx.slot)}|${leg}`;      legSigs.set(slotLeg, (legSigs.get(slotLeg) ?? new Set<string>()).add(sig));    }  }  console.log(`read ${read} transactions for ${target}, ${nulls} null, ${failed} failed`);  const flags = Array.from(legSigs).filter(([, s]) => s.size > 1);  for (const [slotLeg, s] of flags) console.log(`REVIEW ${slotLeg} <- ${Array.from(s).join(", ")}`);  if (flags.length === 0) console.log("no slot holds two transfers with the same source, destination, mint and amount");}run().catch((e: unknown) => {  console.error("detector stopped:", e instanceof Error ? e.message : e);  process.exit(1);});

run: CARBIUM_KEY=$CARBIUM_KEY DUP_LIMIT=8 node main.ts EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

Each failed read and each null answer is counted and printed, and the rest of the run goes on. A null means the node returned no transaction for that signature, which the last section covers.

05

What a flag starts

A flag names the slot, the leg and every signature that shares it. Work each flag in three steps.

  1. Match each signature to one order or invoice in your records.
  2. Check the memo or reference each transaction carried against that order.
  3. Hold any refund or credit for a person to approve. The detector sends nothing back.
$Re-read the flagged signatures before any action, so the decision rests on the transactions as they stand at the time of the check.
06

Where it ends

  • History: the listing reaches back 30 days at most. A duplicate older than that sits outside this check, and an empty page past 30 days marks the index's age limit.
  • Sample size: 8 transactions is a demonstration. Raising DUP_LIMIT adds 50 cells for each transaction read.
  • Parsing: a transfer made through a program that does not parse to a transfer shows no leg, so its amount is missed.
  • Matching: the code compares source, destination, mint and amount. It does not read memos or references, so pairs that differ only there still raise a flag.
  • Null answers: getTransaction can return null for a signature the list shows, most often an old one. The code counts those and skips them.
  • No write path: the check reads and reports. Stopping a duplicate happens in your own payment flow, before the transaction is sent.
07

When it goes wrong

what goes wrongwhat to do
Two different signatures are read as one payment.They are two transactions. Key your payment records on the order and the signature together, so a rebuilt payment is kept as its own row.
getTransaction returns -32015 for a transaction in the list.Set maxSupportedTransactionVersion to 1 with jsonParsed encoding. The script does this already, so a -32015 means the setting was removed.
Every run reports the same flags.Store the flagged signatures with their review result and skip pairs that were already reviewed.
The run prints zero transactions read.Check the key with a plain getSlot call. An unknown key gets 401 at the door as UNKNOWN_KEY, and the fix is to attach the whole key.
A signature from the list returns null on read.Count it and move on. Older signatures can reach below the ledger floor, so a null is expected for old entries.
08

Questions

Can the same signed transaction land twice in one block?

No. The runtime rejects a second copy of signed bytes it has already processed, so the transfer runs once. A rebuilt transfer has a new signature and can land beside the first.

Does a second identical transfer mean the customer paid twice?

Not by itself. Two signatures show two transactions, and only your order records say whether both were wanted. The flag starts that check.

Does the detector stop a duplicate from landing?

No. It reads transactions after they land and sends nothing. Stopping a duplicate belongs in your payment flow, where one order maps to one signature before the send.

How far back can it look?

The listing reaches back 30 days at most. A payment older than that needs a source other than this endpoint.