services
Get a key

library / Use cases / Payments and checkout / UC0083

Mobile checkout return polling

Bring a customer back from a wallet app to the right order state: keep the order on your server, poll for the reference's newest signature past a stored cursor, read its status from the same entry, and size the poll interval against per-plan rates.

By Carbium · Payments and checkout · UC0083 · updated 2026-11-22

01

What happens to the tab during the wallet hop

A mobile checkout hands the payment to a wallet app through a deep link or a Solana Pay request. The moment the wallet takes the screen, the browser tab goes to the background. Mobile browsers freeze or heavily throttle timers in a background tab, and the operating system can close a socket held by a suspended page. Some browsers discard the tab outright, so the customer comes back to a fresh page load with no running script and no memory of the order.

Plan for that and let the page hold nothing that matters. The order, its reference public key and its state live on your server. The page carries only the order id in its URL, and whenever it wakes it asks your server where the order stands. Three events cover every way back, and all three call the same function:

  • visibilitychange when the tab becomes visible again.
  • pageshow, which also fires when the browser restores the page from its back-forward cache.
  • A plain page load, for a tab the browser threw away.

A subscription seems the natural fit, since the chain tells you when the payment lands. But `signatureSubscribe` sends one confirmation, then ends, and a socket that died during the hop never hears it. A subscription suits a desktop page that stays open. On mobile, a read made after the fact works whatever happened to the page in between.

02

The poll on return

The poll is one read against one RPC endpoint. It lists the signatures that mention the order's reference, newer than a cursor, and each entry in the answer carries the transaction's error field and its confirmation status. The same call tells you that the payment landed and how far it has got.

ReadRPC methodWhat the answer means
Find the paymentgetSignaturesForAddress with untilAn empty list means the wallet has not paid yet. A signature means a transaction mentioned the reference.
Read its statusThe same entryconfirmationStatus is processed, confirmed or finalized, and err is null or the failure. Both come back with the signature, so a late return still settles.

The cursor is the newest signature that existed before the customer left. Passing it as until makes the call return only what arrived after it, newest first, so every poll after the hop is a short list instead of a re-read of the address history. A fresh reference key per order has no signatures at all, and then the cursor is empty and the first signature that appears is the payment. A shared address, such as a till wallet or a payment-link wallet, already has history, so your server reads its newest signature when the order opens and stores it with the order.

The two getSignaturesForAddress calls in the script below, the cursor read and the poll, both pass confirmed, so a signature the poll finds is at confirmed commitment or higher.

An entry with err set means the transaction landed and failed. Show the customer a failed payment and keep the order open for another try. A clean entry can settle the moment the poll finds it, whether the customer returns after ten seconds or ten minutes.

03

The interval budget

Each poll is one getSignaturesForAddress call, and that method costs 50 cells per call at 0.24, 1.2, 100 and 500 req/s on Free, Dev, Business and Pro. All keys on an account share that rate. Divide the plan rate by the poll rate of one checkout and you have the number of checkouts that can poll at once:

Poll everyReq/s per checkoutFreeDevBusinessPro
3 s0.33033001500
5 s0.2165002500
10 s0.121210005000

Rerun the arithmetic with your own interval. A hit needs no further call, since its status fields come with the entry. Free cannot hold even one checkout at 3 seconds, which is a reason to widen the interval on small plans and tighten it only when the plan has room.

Two habits keep the count honest. Poll only orders whose customer has come back, because an order whose tab is still in the wallet app will not pay in the next second. And poll once per order on the server, whatever number of tabs ask about it: the tabs read your server's last answer. A crowd returning together, as after an event, is absorbed by the burst allowance of 1,024 cells or one second of the rate, whichever is larger. That is at least 20 polls of 50 cells at once, and 100 on Business and 500 on Pro.

04

The return poll 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. Pass an order's reference as the first argument. With no argument the USDC mint stands in for the reference, since that address gets new signatures every second and the demo has something to find. PLAN (free, dev, business or pro, default business) picks the interval from a small table in the file: 10 s, 5 s, 3 s and 3 s. POLL_MS overrides it, and WAIT_MS defaults to 20000, so a run ends inside 30 seconds.

main.ts
// UC0083 · Mobile checkout return polling// https://carbium.sh/library/usecase/mobile-checkout-return-polling// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only return poll: one poll step moves an order cursor from open to watching to paid to settled.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type 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 url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";// With no argument the USDC mint stands in for an order reference: it always has new signatures.const reference = address(process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");// Poll interval per plan, in ms: small plans have little rate to spend on one checkout.const planInterval: Record<string, number> = { free: 10000, dev: 5000, business: 3000, pro: 3000 };const interval = Number(process.env.POLL_MS ?? planInterval[process.env.PLAN ?? "business"] ?? 3000);const waitMs = Number(process.env.WAIT_MS ?? 20000);const commitment = "confirmed";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));const msg = (e: unknown) => (e instanceof Error ? e.message : String(e));const started = Date.now();// The listed entry already carries err and confirmationStatus, so a late return needs no second read.type Hit = { signature: Signature; err: unknown; confirmationStatus: string | null };type Order = { stage: "open" | "watch" | "paid" | "settled"; polls: number; after?: Signature; paid?: Hit };// One step: takes the order cursor, makes the one read its stage needs, returns the next cursor.async function poll(order: Order): Promise<Order> {  try {    if (order.stage === "open") {      // The cursor is the newest signature that exists now; a server stores it when the order opens.      const [head] = await rpc.getSignaturesForAddress(reference, { limit: 1, commitment }).send();      return { ...order, stage: "watch", after: head?.signature };    }    if (order.stage === "watch") {      const polls = order.polls + 1;      try {        const page = await rpc.getSignaturesForAddress(reference, { limit: 10, until: order.after, commitment }).send();        const paid = page[page.length - 1]; // newest first, so the last is the earliest after the cursor        return { ...order, polls, paid, stage: paid ? "paid" : "watch" };      } catch (e) { console.error(`poll ${polls} failed:`, msg(e)); return { ...order, polls }; }    }    const elapsed = Date.now() - started;    const s = order.paid;    const err = JSON.stringify(s?.err ?? null, (_k, v) => (typeof v === "bigint" ? String(v) : v));    console.log(`polls ${order.polls}, ${elapsed} ms, ${s?.signature} status ${s?.confirmationStatus ?? "unknown"} err ${err}`);    return { ...order, stage: "settled" };  } catch (e) {    console.error("cursor read failed:", msg(e));    process.exit(1);  }}let order = await poll({ stage: "open", polls: 0 });while (order.stage !== "settled") {  if (order.stage === "watch") {    if (Date.now() - started >= waitMs) {      console.log(`polls ${order.polls}, ${Date.now() - started} ms, nothing new for ${reference}`);      process.exit(2);    }    await sleep(interval);  }  order = await poll(order);}

run: CARBIUM_KEY=$CARBIUM_KEY node main.ts EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

It reads the newest signature as the cursor, sleeps one interval, and polls with until set to the cursor. The first poll that returns signatures ends the loop, and the script keeps the last entry of that page, which is the earliest after the cursor on a fresh reference. Then it prints the polls made, the elapsed time and the entry's status with its error field. A failed poll is printed and the loop goes on. Exit code 0 means a signature was found, 2 means nothing new arrived in time, and 1 is a missing key or a failed cursor read.

On a real order, the cursor read belongs to the moment your server creates the order, and the loop belongs to the request a returning page makes. The script does both in one run so you can watch the whole path.

05

Where it ends

  • A customer who never returns never calls your server, so no poll starts for that order. Run a server-side poll for every order still open, on a longer interval, and expire the order at a time you choose. Many payments land from customers who closed the tab.
  • A signature for the reference shows that a transaction mentioned it. It does not show the amount, the recipient or the asset. Run the amount and recipient checks from Solana Pay confirmation before the order is marked paid.
  • The address index behind getSignaturesForAddress keeps up to 30 days. An order older than that looks unpaid, so store the signature when you find it.
  • The script asks for 10 signatures per page, though the method allows more. If more than 10 arrived since the cursor, the page holds only the newest 10 and its last entry is not the earliest payment. A fresh reference per order never gets there, and the USDC demo can. Two payments that mention one reference between polls give you the earlier one, so use a new reference per order.
  • The return poll only reads; building the payment request, the wallet side and signing happen elsewhere.
06

When it goes wrong

what goes wrongwhat to do
The page keeps polling after the customer comes back and the order never updates.The tab was discarded and reloaded, so the old timer is gone and the new page has no state. Keep the order on the server and have every load, pageshow and visibilitychange ask it for the current state.
Resuming the tab fires a pile of queued poll ticks at once.Run one poll at a time per order, clear the timer when the page hides and start a single new loop when it shows. The server also answers from its stored result, so extra page requests cost no RPC calls.
The payment is missed because the cursor was read after the customer paid.Read and store the cursor when the order is created, before the wallet opens. A cursor taken later can sit past the payment, and until then hides it.
A customer returns long after paying and the order stays pending.Read err and confirmationStatus from the entry the poll lists. They come with the signature for as long as the address index lists it, so a late return settles the same as a quick one.
A failed transaction marks the order paid.A listed signature can belong to a transaction that errored. Check the entry's error field first, then confirm amount and recipient before settling.
Free rate runs out with a handful of open checkouts.Widen the interval using the table, poll only returned customers, and move to a plan whose rate covers your count of open orders.
07

Questions

Why not keep a WebSocket open from the checkout page?

The page is in the background while the wallet app is in front, and the browser or the operating system can freeze it or close its socket. A confirmation sent in that window is lost, while a poll made on return reads the result whenever it asks.

Is the cursor needed for a fresh reference per order?

No. A new reference has no signatures, so the first one that appears is the payment. The cursor matters when you poll an address that already has history, such as a till wallet or a mint.

Which commitment should the poll use?

Both getSignaturesForAddress calls in the script, the cursor read and the poll, pass confirmed. The entry the poll returns carries confirmationStatus, so you can hold the final settlement step until it reads finalized. Name the commitment in each call so the result does not depend on the client.

How long should an order stay pollable?

Set the expiry well inside the 30 days the address index keeps, since a reference older than that looks unpaid. A few minutes to a few hours suits most checkouts.