Query Token Balance
Check your stablecoin balance using thegetTokenAccountBalance RPC method:
Watch for Incoming Transfers
Subscribe to your token account for real-time payment notifications using theaccountNotifications RPC method:
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 below.
Note that for production applications, you should consider a more robust
streaming solution. Some options include:
Parsing Transaction History
Solana has RPC methods that allow you to fetch an account’s transaction history (getSignaturesForAddress) and get
the details of a transaction
(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).
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.
Reconcile Payments with Memos
When senders include memos (invoice IDs, order numbers), you can extract them from the transaction’s message using thegetTransaction 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:
Protections
A few failure modes to avoid. The checkout tutorial’s Confirm payments from your backend step implements all of them in one confirm endpoint, and its go-live step 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, andconfirmedreports the same block, so code that checksconfirmed(as the checkout tutorial does) is equally safe. See settlement and 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 (a fresh address added to the transfer as a read-only account), not by the amount.