---
id: UC0002
title: "Solana Pay confirmation"
url: https://carbium.sh/library/usecase/solana-pay-confirmation
collection: Use cases
category: Payments and checkout
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Solana Pay confirmation

Find and verify a Solana Pay payment from your server: why findReference() gets a 403 from a shared endpoint, what its two reads cost per call, how to poll inside a request budget, and a Node check that validates the amount.

## Where the 403 comes from

`findReference()` from `@solana/pay` has no network code of its own. It takes a web3.js `Connection` and sends one `getSignaturesForAddress` call for the reference key in the usual case, and pages back with `before` when a page comes back full. A 403 is therefore the answer of whatever URL that `Connection` points at, and the library has no part in it.

To test that, repeat the call with `curl` from the machine that runs your code. If `curl` gets the 403 too, the endpoint refuses you. If `curl` succeeds, the refusal depends on where your code runs, and a browser origin is the usual suspect.

Shared public endpoints often limit some methods, some origins and heavy callers, and a payment page is all three: it runs in a browser, it polls, and it asks for an address history. The fix is an endpoint you hold a key for, called from your server.

On Carbium one domain, `services.carbium.sh`, [serves RPC over HTTPS](https://carbium.sh/docs#endpoints). Send your [key](https://carbium.sh/docs#auth) in the `x-api-key` header from your server. The checkout page asks your server whether an order is paid, and your server asks Carbium, so the key never reaches a browser bundle.

> In the web3.js 1.x line that `@solana/pay` builds on, a `Connection` takes `httpHeaders` in its config, so `new Connection(url, { httpHeaders: { "x-api-key": key } })` is the whole change to an existing `findReference()` call.

## What the check sends to the endpoint

A Solana Pay payment is confirmed by two reads. The first finds the signature: it lists the signatures that mention the order's reference key, and an empty page means the wallet has not paid yet. The second reads that transaction, to check that it succeeded and moved the right amount to the right wallet. `findReference()` does the first, and `validateTransfer()` fetches the transaction and checks it for the second.

| Read | RPC method | Cells per call | Free req/s | Dev req/s | Business req/s | Pro req/s |
|---|---|---|---|---|---|---|
| Find the reference | getSignaturesForAddress | 50 | 0.24 | 1.2 | 100 | 500 |
| Read the transaction | getTransaction | 50 | 0.24 | 1.2 | 5 | 25 |

Each call [costs 50 cells](https://carbium.sh/docs#rpc), and all keys on an account [share one budget](https://carbium.sh/docs#limits). The reference is a fresh public key per order. The wallet adds it to the transfer as a read-only account, and it never holds funds, so the signature list is the only place the payment shows up under that key.

An empty signature page is the normal state of an unpaid order. `findReference()` raises `FindReferenceError` for it. Treat that error as pending and keep waiting. A 403, a 429 or a timeout is a real failure and needs its own branch.

## A payment check in one file

The script reads `CARBIUM_KEY` and sends every call to `https://services.carbium.sh`, or to `CARBIUM_RPC_URL` when you set it, with the key in `x-api-key`. It needs `REFERENCE`, and takes `RECIPIENT`, `MINT`, `AMOUNT`, `POLL_MS` and `WAIT_MS` as options. `RECIPIENT` needs `AMOUNT` with it, and the script exits at once with a message when `AMOUNT` is missing. `POLL_MS` defaults to 10000 and `WAIT_MS` to 20000, so the script gives up after 20 s unless told otherwise.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY REFERENCE=<reference pubkey> RECIPIENT=<wallet> AMOUNT=<base units> node main.ts`)

```ts
// UC0002 · Solana Pay confirmation
// https://carbium.sh/library/usecase/solana-pay-confirmation
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only Solana Pay check: find the payment for a reference key, then verify it on chain.
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 reference = process.env.REFERENCE;
if (!reference) { console.error("Set REFERENCE to the order's reference public key."); process.exit(1); }
const ref = address(reference);
const recipient = process.env.RECIPIENT; // wallet that should receive the payment; unset skips the amount check
const mint = process.env.MINT; // set for an SPL payment, unset for SOL
if (recipient && !process.env.AMOUNT) { console.error("Set AMOUNT (integer base units) when RECIPIENT is set."); process.exit(1); }
const amount = BigInt(process.env.AMOUNT ?? "0"); // integer base units
const pollMs = Number(process.env.POLL_MS ?? 10000);
const deadline = Date.now() + Number(process.env.WAIT_MS ?? 20000);
const commitment = "finalized";

const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

// findReference: an empty page means not paid yet; anything thrown is a real failure.
async function findReference() {
  while (Date.now() < deadline) {
    const page = await rpc.getSignaturesForAddress(ref, { limit: 10, commitment }).send();
    const first = [...page].reverse().find((s) => s.err === null); // oldest successful signature
    if (first) return first;
    await sleep(pollMs);
  }
  return undefined;
}

try {
  const found = await findReference();
  if (!found) { console.error("No payment found for this reference yet."); process.exit(2); }
  console.log(`found ${found.signature} in slot ${found.slot}`);
  // version 1: mainnet carries v1 transactions, and a lower value answers -32015 for one
  const tx = await rpc.getTransaction(found.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment }).send();
  const meta = tx?.meta;
  if (!tx || !meta || meta.err) { console.error("Transaction failed or could not be read."); process.exit(3); }
  const keys = [...tx.transaction.message.accountKeys, ...(meta.loadedAddresses?.writable ?? []), ...(meta.loadedAddresses?.readonly ?? [])];
  if (!keys.includes(ref)) { console.error("The reference is not among the transaction's accounts."); process.exit(3); }
  if (recipient) {
    // token balances are matched by owner wallet and mint; SOL by the recipient's lamport difference
    const sum = (rows: readonly { mint: string; owner?: string; uiTokenAmount: { amount: string } }[] | null | undefined) =>
      (rows ?? []).filter((b) => b.mint === mint && b.owner === recipient).reduce((n, b) => n + BigInt(b.uiTokenAmount.amount), 0n);
    const i = keys.indexOf(address(recipient));
    const paid = mint
      ? sum(meta.postTokenBalances) - sum(meta.preTokenBalances)
      : i < 0 ? 0n : BigInt(meta.postBalances[i]!) - BigInt(meta.preBalances[i]!);
    console.log(`paid ${paid} base units to ${recipient}, wanted ${amount}`);
    if (paid < amount) process.exit(4);
  } else {
    console.log("finalized, executed, reference present; set RECIPIENT and AMOUNT to check the payment");
  }
} catch (e) {
  console.error("RPC call failed:", e instanceof Error ? e.message : e);
  process.exit(1);
}
```

It polls `getSignaturesForAddress` for the reference until a signature appears or `WAIT_MS` runs out, takes the oldest successful signature of the page, then reads the transaction with `getTransaction`. The read passes `maxSupportedTransactionVersion: 1`, because mainnet carries v1 transactions and the RPC answers -32015 for one when the value is absent or 0. It checks that the transaction ran without error and that the reference is among its accounts. With `RECIPIENT` set it also compares what that wallet received with `AMOUNT`, in integer base units: the lamport difference for SOL, or the token balance difference when `MINT` is set. For tokens, `RECIPIENT` is the wallet that owns the token account.

Exit codes tell your caller what happened: 0 for a verified payment, 2 when nothing was found in time, 3 for a failed or unreadable transaction, 4 for a payment short of `AMOUNT`, and 1 for a missing setting or an RPC error such as a refused call. A v1 payment is read like any other and ends in 0, 3 or 4.

The demo is read-only. Without `RECIPIENT` it checks the reference only, so run it against any busy public address to see the whole path work, then against a real order's reference with its wallet and amount.

## Poll inside the budget

Each open checkout that polls adds 50 cells per poll to the account's budget, and the table gives the ceiling per plan. Take one poll every 10 seconds per checkout, which is 0.1 req/s each. The Free rate of 0.24 req/s then covers 2 open checkouts, Dev at 1.2 req/s covers 12, and Business at 100 req/s covers 1000. Rerun the arithmetic with your own interval, and remember that each find is followed by one `getTransaction`.

A call over its rate gets a 429 with a retry-after hint. Sleep for the hint before the next poll. [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) covers alerting on those 429s.

When open checkouts outgrow the poll budget, switch to a subscription, which sends you the signature when the payment lands and needs no polling.

- Open one `logsSubscribe` per open order, with the reference as the mention. The first notification for that reference carries the signature.
- A subscription [opens at 5, 25 or 200 credits](https://carbium.sh/docs#websocket) by filter weight and then costs 20 credits per MiB sent. A logs-mentions filter sits in the 25 tier. Connection and subscription counts are capped per account by tier, and Free carries 5 sockets.
- After the notification, do one `getTransaction` and run the same checks. Close the subscription when the order pays or expires.

## Where it ends

- The address index behind `getSignaturesForAddress` [keeps up to 30 days](https://carbium.sh/docs#migrate), and an empty page past that is its age limit. A reference older than 30 days looks unpaid. Store the signature in your own database the moment you find it, and expire orders well inside that window.
- The amount check covers one recipient and one asset: SOL, or one mint paid to the wallet that owns the token account. Split payments, memos, transfer fees on a mint and a recipient that also pays the transaction fee need their own rules. For SOL, a fee payer's lamport difference includes the fee.
- The script takes the oldest successful signature of the first page of 10. A reference reused by several transactions gives you the first one, so issue a new reference per order.
- It reads and verifies. Building the payment request, the wallet side and anything that signs or sends are outside it.
- A 403 from an endpoint other than Carbium comes from that endpoint's own rules, and nothing here changes them. Point the `Connection` or the script at the Carbium URL and send the key in the header.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The 403 stays after the URL changes. | Another `Connection` still holds the old URL, often in a second module or in the browser build. Log the host the code calls at start-up, never the key, and search the bundle for the old URL. |
| `FindReferenceError` cancels the order. | An empty page means the wallet has not paid yet. Keep polling until the order expires, and cancel only on a real error or on expiry. |
| Every visitor's browser polls and the 429s start. | Poll from your server, once per open order, at an interval taken from the table. Sleep for the retry-after value before the next poll. |
| An old order shows as never paid. | The address index keeps up to 30 days. Save the signature when you first find it and reconcile older orders from your own record. |
| An order is marked paid as soon as a signature appears. | A signature only shows that a transaction mentioned the reference. Read the transaction and check that it succeeded, who received the funds and how much. |
| Two orders share a reference and one payment settles both. | Generate a new reference key for every order and never reuse it. |

## Questions

### Does findReference() work against Carbium?

It sends one `getSignaturesForAddress` call in the usual case, and pages back with `before` when a page comes back full. Carbium serves that method at 50 cells. Give it a `Connection` that points at `https://services.carbium.sh` with the key in `x-api-key`.

### Do I still need @solana/pay for the check?

No, the server check works without it, though `validateTransfer()` remains an option if you already use it. The library builds payment links and request URLs. The check on your server is two reads, and the script does both with `@solana/kit`, including the recipient and amount test.

### Can the checkout page call Carbium directly?

It can, but the key would sit in the page for anyone to copy. Keep the key on your server and let the page ask your server whether an order is paid.

### What does the script do when the payment is short?

It prints what the recipient received against what you wanted and exits with 4. Your caller can then hold the order and ask the buyer to top it up.

## Related

- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
