> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Verification Tools

> Verify incoming stablecoin payments and reconcile them with your orders.

Tokens land in your wallet the moment a transaction confirms. There is no action
required by the recipient. Solana atomically increments the receiver's token
account balance and decrements the sender's balance. In this guide, we cover
some helpful tools for understanding your token account balance and watching for
incoming payments.

## Query Token Balance

Check your stablecoin balance using the
[`getTokenAccountBalance`](/developers/docs/rpc/http/gettokenaccountbalance) RPC method:

```typescript
import {
  createSolanaRpc,
  address,
  type Address,
  type Signature
} from "@solana/kit";
import {
  findAssociatedTokenPda,
  TOKEN_PROGRAM_ADDRESS
} from "@solana-program/token";

const rpc = createSolanaRpc("https://api.mainnet.solana.com");
const USDC_MINT = address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");

async function getBalance(walletAddress: Address) {
  // Derive the token account address
  const [ata] = await findAssociatedTokenPda({
    mint: USDC_MINT,
    owner: walletAddress,
    tokenProgram: TOKEN_PROGRAM_ADDRESS
  });

  // Query balance via RPC
  const { value } = await rpc.getTokenAccountBalance(ata).send();

  return {
    raw: BigInt(value.amount), // "1000000" -> 1000000n
    formatted: value.uiAmountString, // "1.00"
    decimals: value.decimals // 6
  };
}
```

## Watch for Incoming Transfers

Subscribe to your token account for real-time payment notifications using the
`accountNotifications` RPC method:

```typescript
import {
  createSolanaRpc,
  createSolanaRpcSubscriptions,
  getBase64Codec,
  type Address
} from "@solana/kit";
import { getTokenCodec } from "@solana-program/token";

const rpc = createSolanaRpc("https://api.mainnet.solana.com");
const rpcSubscriptions = createSolanaRpcSubscriptions(
  "wss://api.mainnet.solana.com"
);

async function watchPayments(
  tokenAccountAddress: Address,
  onPayment: (amount: bigint) => void
) {
  const abortController = new AbortController();

  // Start from the current balance, so the first notification reports only
  // the new transfer and not the whole balance
  const { value } = await rpc
    .getTokenAccountBalance(tokenAccountAddress, { commitment: "confirmed" })
    .send();
  let previousBalance = BigInt(value.amount);

  const subscription = await rpcSubscriptions
    .accountNotifications(tokenAccountAddress, {
      commitment: "confirmed",
      encoding: "base64"
    })
    .subscribe({ abortSignal: abortController.signal });

  for await (const notification of subscription) {
    const [data] = notification.value.data;
    const dataBytes = getBase64Codec().encode(data);
    const token = getTokenCodec().decode(dataBytes);
    if (token.amount > previousBalance) {
      const received = token.amount - previousBalance;
      onPayment(received);
    }
    previousBalance = token.amount;
  }
  abortController.abort();
}
```

Note here that we are using RPC Subscriptions and a websocket connection to the
Solana network.

Each notification contains a base64 encoded string of the token account data.
Because we know the account we are looking at is a token account, we can decode
the data using the `getTokenCodec` method from the `@solana-program/token`
package.

The function reads the current balance before it subscribes, so each payment
is the difference from the previous balance, not the account's whole balance.
A balance change tells you that funds arrived, not who sent them or which order
they pay for, and two transfers that land close together can arrive as one
change. To match each payment to an order, read its transaction, as in
[Parsing Transaction History](#parsing-transaction-history) below.

Note that for production applications, you should consider a more robust
streaming solution. Some options include:

- [Alchemy](https://docs.alchemy.com/reference/subscription-api)
- [Triton](https://docs.triton.one/chains/solana/streaming)
- [Helius](https://www.helius.dev/docs/data-streaming)
- [QuickNode](https://www.quicknode.com/docs/solana/subscriptions)

## Parsing Transaction History

Solana has RPC methods that allow you to fetch an account's transaction history
([`getSignaturesForAddress`](/developers/docs/rpc/http/getsignaturesforaddress)) and get
the details of a transaction
([`getTransaction`](/developers/docs/rpc/http/gettransaction)). To parse transaction
history, we fetch recent signatures for our token account, then retrieve each
transaction's pre/post token balances. By comparing our ATA's balance before and
after each transaction, we can determine the payment amount and direction
(incoming vs outgoing).

```typescript
type Payment = {
  signature: Signature;
  timestamp: bigint | null;
  amount: bigint;
  type: "incoming" | "outgoing";
};

async function getRecentPayments(
  tokenAccountAddress: Address,
  limit = 100
): Promise<Payment[]> {
  const signatures = await rpc
    .getSignaturesForAddress(tokenAccountAddress, { limit })
    .send();
  const payments: Payment[] = [];

  for (const sig of signatures) {
    const tx = await rpc
      .getTransaction(sig.signature, {
        maxSupportedTransactionVersion: 1,
        encoding: "json"
      })
      .send();

    if (!tx?.meta?.preTokenBalances || !tx?.meta?.postTokenBalances) continue;

    // Find our ATA's index in the transaction
    const accountKeys = tx.transaction.message.accountKeys;
    const ataIndex = accountKeys.findIndex((key) => key === tokenAccountAddress);
    if (ataIndex === -1) continue;

    // Compare pre/post balances for our ATA
    const pre = tx.meta.preTokenBalances.find(
      (b) => b.accountIndex === ataIndex && b.mint === USDC_MINT
    );
    const post = tx.meta.postTokenBalances.find(
      (b) => b.accountIndex === ataIndex && b.mint === USDC_MINT
    );

    const preAmount = BigInt(pre?.uiTokenAmount.amount ?? "0");
    const postAmount = BigInt(post?.uiTokenAmount.amount ?? "0");
    const diff = postAmount - preAmount;

    if (diff !== 0n) {
      payments.push({
        signature: sig.signature,
        timestamp: tx.blockTime,
        amount: diff > 0n ? diff : -diff,
        type: diff > 0n ? "incoming" : "outgoing"
      });
    }
  }

  return payments;
}
```

To identify the counterparty, you can scan the transaction's token balances for
another account whose balance changed in the opposite direction—if you received
funds, look for an account whose balance decreased by the same amount.

Because SPL token transfers can exist beyond just payments between users, this
approach might yield some transactions that are not payments. A good alternative
here is to use Memos.

### Limitations of Pre/Post Balance Parsing

The approach above works well for simple payment flows. However, companies
processing payments at scale often need more granular and real-time data:

- **Per-instruction breakdown:** A single transaction can contain multiple
  transfers. Pre/post balances only show the net change, not individual
  transfers.
- **Multi-party transactions:** Complex transactions (swaps, batch payments)
  involve multiple accounts. Balance diffs don't reveal the complete flow of
  funds.
- **Audit requirements:** Financial compliance often requires reconstructing
  exact transfer sequences, not just final balances.

For production systems handling high volumes, consider dedicated
[indexing solutions](/developers/docs/payments/accept-payments/indexing) that parse
individual transfer instructions and provide transaction-level detail.

## Reconcile Payments with Memos

When senders include memos (invoice IDs, order numbers), you can extract them
from the transaction's message using the `getTransaction` RPC method and the
`jsonParsed` encoding. The RPC only parses memos from some Memo program
versions. For others, such as the program `@solana-program/memo` uses, the
instruction carries just `programId` and base58 `data`, so match on the program
id and decode the data yourself:

```typescript
import { getBase58Encoder, getUtf8Decoder } from "@solana/kit";
import { SUPPORTED_MEMO_PROGRAM_ADDRESSES } from "@solana-program/memo";

// SUPPORTED_MEMO_PROGRAM_ADDRESSES lists the current Memo program (used by
// @solana-program/memo) and the legacy v1 and v3 programs

// `transaction` is a getTransaction response with jsonParsed encoding
function extractMemos(transaction: any): string {
  const { instructions } = transaction.transaction.message;
  let memos = "";
  for (const instruction of instructions) {
    if (instruction.program === "spl-memo") {
      // The RPC parsed the instruction for us
      memos += instruction.parsed + "; ";
    } else if (
      SUPPORTED_MEMO_PROGRAM_ADDRESSES.includes(instruction.programId) &&
      instruction.data
    ) {
      // Not parsed by the RPC: decode the base58 instruction data as UTF-8
      const bytes = getBase58Encoder().encode(instruction.data);
      memos += getUtf8Decoder().decode(bytes) + "; ";
    }
  }
  return memos;
}

async function getTransactionMemo(
  signature: Signature
): Promise<string | null> {
  const tx = await rpc
    .getTransaction(signature, {
      maxSupportedTransactionVersion: 1,
      encoding: "jsonParsed"
    })
    .send();
  if (!tx) return null;
  return extractMemos(tx);
}
```

## Protections

A few failure modes to avoid. The checkout tutorial's
[Confirm payments from your backend](/developers/docs/payments/checkout/backend) step
implements all of them in one confirm endpoint, and its
[go-live step](/developers/docs/payments/checkout/go-live) covers the edge cases real
customers hit.

- **Trusting the frontend.** A checkout page says "payment complete"—but did the
  transaction actually land? Always verify server-side by querying the RPC.
  Frontend confirmations can be spoofed.

- **Acting on "processed" status.** Solana transactions go through three stages:
  processed → confirmed → finalized. A "processed" transaction can still be
  dropped if its block is skipped. Fulfill an order only once its payment is
  `finalized`. On mainnet that takes roughly 150 milliseconds, and `confirmed`
  reports the same block, so code that checks `confirmed` (as the checkout
  tutorial does) is equally safe. See
  [settlement and finality](/developers/docs/defi/finality).

- **Ignoring the mint.** Anyone can create a token called "USDC". Validate that
  the token account's mint matches the real stablecoin mint address and token
  program, not just the token name.

- **Double-fulfillment.** Your webhook fires, you ship the order. Network
  hiccup, webhook fires again. Now you've shipped twice. Store processed
  transaction signatures and check before fulfilling.

- **Matching by amount alone.** Transactions are public, so anyone who sees a
  payment of the right amount to your address could claim it for their own
  order. Match each payment to its order by a unique
  [reference](/developers/docs/tools/solana-pay/specification/version1-1#reference) (a
  fresh address added to the transfer as a read-only account), not by the
  amount.
