Commerce Kit is no longer maintainedCommerce Kit packages no longer receive updates or fixes. For new payment
integrations, use Solana Pay.
@solana-commerce/headless package provides framework-agnostic functions
for building commerce payment flows. These tools help create payment request
objects, generate Solana Pay URLs, and verify onchain payments. The package is
designed to work in any JavaScript environment: React, Vue, Svelte, vanilla JS,
Node.js, or serverless functions.
Installation
Payment Request Functions
These functions create standardized payment request objects for different commerce patterns. They don’t perform any blockchain operations—they simply structure data for use in wallets, Solana Pay URLs, or custom payment UIs.createBuyNowRequest()
Creates a standardized payment request for a single product purchase.
Parameters
-
recipient(string, required) - Merchant wallet address (base58-encoded Solana public key) that will receive the payment. -
product(any, required) - Product object containing:price(number, required) - Product price. The unit depends on context (e.g., lamports for SOL, minor units for tokens).currency(string, required) - Payment currency. Can be'SOL'or a token mint address.name(string, required) - Product name, used for default memo/label if not provided.- Additional fields (id, description, image, etc.) are passed through in the
productsarray.
-
options(object, optional) - Customization options:memo(string) - Onchain memo for the transaction. Default:"Purchase: {product.name}".label(string) - Display label for the payment request (used in Solana Pay). Default:product.name.message(string) - Success message shown after payment. Default:"Thank you for purchasing {product.name}!".
Returns
APaymentRequest object containing:
recipient- The merchant wallet addressamount- The product price (copied fromproduct.price)currency- Payment currency (copied fromproduct.currency)products- Array containing the single productmemo- Transaction memo (option or default: “Purchase: (product.name)”)label- Payment label (option or default: “product.name”)message- Success message (option or default: “Thank you for purchasing (product.name)!”)
createCartRequest()
Creates a payment request for multiple products in a shopping cart.
Parameters
-
recipient(string, required) - Merchant wallet address that will receive the payment. -
products(any[], required) - Array of product objects. -
options(object, optional) - Customization options:currency(string) - Payment currency for the entire cart.memo(string) - Onchain memo. Default:"Cart purchase (products.length items)".label(string) - Payment label. Default:"Cart Checkout".message(string) - Success message. Default:"Thank you for your purchase!".
Returns
APaymentRequest object with:
recipient- The merchant wallet addressamount- Sum of all product prices (products.reduce((sum, p) => sum + p.price, 0))currency- Payment currency (from options, or undefined)products- The array of productsmemo,label,message- Option values or defaults
createTipRequest()
Creates a payment request for tips or donations with a user-defined amount.
Parameters
-
recipient(string, required) - Wallet address of the tip recipient (creator, streamer, charity, etc.). -
amount(number, required) - Tip amount. Unit depends on currency (lamports for SOL, minor units for tokens). -
options(object, optional) - Customization options:currency(string) - Payment currency. Default: undefined (typically treated as SOL by consumers).memo(string) - Onchain memo. Default:"Thank you for your support!".label(string) - Payment label. Default:"Tip".message(string) - Success message. Default:"Thanks for the tip!".
Returns
APaymentRequest object with:
recipient- The tip recipient’s wallet addressamount- The tip amountcurrency- Payment currency (from options, or undefined)memo,label,message- Option values or defaults
Payment Verification Functions
These functions interact with Solana to verify transactions and wait for confirmations. They require a Solana RPC client from the@solana/kit library.
verifyPayment()
Checks that a transaction exists onchain. It is meant to also validate the
payment amount, recipient, and token, but in @solana-commerce/headless@0.1.1
those checks are incomplete (see the warning below).
Parameters
-
rpc(Rpc<SolanaRpcApi>, required) - RPC client from@solana/kit. Create withcreateSolanaRpc(rpcUrl). -
signatureString(string, required) - Transaction signature (base58-encoded) to verify. -
expectedAmount(number, optional) - Expected payment amount to validate. Unit should match the currency:- For SOL: lamports (1 SOL = 1,000,000,000 lamports)
- For SPL tokens: minor units based on token decimals (e.g., USDC uses 6 decimals)
-
expectedRecipient(string, optional) - Expected recipient wallet address. If provided (along withexpectedAmount), the function validates that the recipient received at least this amount. If not provided, validation is skipped. -
expectedMint(string, optional) - SPL token mint address. Only required for SPL token transfers. If not provided, the function assumes SOL transfer.
Returns
APromise<PaymentVerificationResult> object:
Verification Logic
The function performs these checks:- Signature Validity: Checks that the signature is valid.
-
Transaction Existence: Fetches the transaction using
rpc.getTransaction(). If not found, returnsverified: false. - Confirmation Status: Checks that the transaction has landed onchain.
-
SOL Transfer Validation (if
expectedRecipientandexpectedAmountprovided, and noexpectedMint):- Finds the recipient’s account index in the transaction
- Compares
preBalancesandpostBalancesto calculate balance delta - Verifies delta is at least
expectedAmount
-
SPL Token Transfer Validation (if
expectedMintprovided):- Derives the recipient’s Associated Token Account (ATA) for both Token Program and Token-2022 Program
- Checks
postTokenBalancesfor a matching ATA with the expected mint - Verifies the token amount is at least
expectedAmount
Security Considerations
- Client-Side Verification: This function fetches transaction data from RPC. Do not expose your RPC URL to the client.
- Finalization: The function checks for confirmed transactions, but for
high-value payments, consider waiting for
finalizedstatus.
As of
@solana-commerce/headless@0.1.1, verifyPayment() only confirms that
the transaction exists and has a blockTime. The SPL token check never runs,
and the SOL amount check runs only when the recipient appears in the
transaction, so a transfer to a different wallet or of a different token can
return verified: true. Do not use verified: true alone to release goods:
validate the transfer yourself, for example with findReference and
validateTransfer from @solana/pay, or by comparing preTokenBalances and
postTokenBalances.It also does not check which order the payment is for (there is no reference
check), and it does not remember signatures it has already accepted, so the
same payment can be presented for two orders. Before you fulfill an order, also match the payment to the order (for example by a
Solana Pay reference)
and record each signature once. Run the check on your server, never only in
the browser. Confirm payments from your
backend shows the full set of checks.waitForConfirmation()
Polls the blockchain until a transaction reaches confirmed or finalized status,
or times out.
Parameters
-
rpc(Rpc<SolanaRpcApi>, required) - RPC client from@solana/kit. -
signatureStr(string, required) - Transaction signature to wait for. -
timeoutMs(number, optional) - Maximum time to wait in milliseconds. Default:30000(30 seconds).
Returns
Promise<boolean>- Returnstrueif transaction reachesconfirmedorfinalizedstatus within the timeout,falseotherwise.
Solana Pay Functions
These functions generate Solana Pay URLs and styled QR codes for mobile wallet scanning.createSolanaPayRequest()
Creates a Solana Pay URL and a styled QR code.
Parameters
-
request(TransferRequestURLFields, required) - Solana Pay transfer request fields:recipient- Recipient public key (usecreateRecipient(address)from@solana-commerce/solana-pay)amount- (optional)bigintamount scaled to 9 decimals: lamports for SOL. The encoder always divides by 1e9, so for a 6-decimal token such as USDC pass1_000_000_000nfor 1 USDC.splToken(optional) - SPL token mint public key (usecreateSPLToken(address))reference(optional) - Reference public key for trackinglabel(optional) - Merchant namemessage(optional) - Success messagememo(optional) - Onchain memo
-
options(SolanaPayRequestOptions, required) - QR code styling options:size(number) - QR code width/height in pixels. Default:256.background(string) - Background color (hex/rgb). Default:'white'.color(string) - QR code color (hex/rgb). Default:'black'.margin(number) - Margin around QR code in modules.errorCorrectionLevel('L' | 'M' | 'Q' | 'H') - Error correction level. Higher levels allow more damage but create denser codes.logo(string) - Logo image URL to embed in center of QR code.logoSize(number) - Logo size as percentage of QR code size.logoBackgroundColor(string) - Background color behind logo.logoMargin(number) - Margin around logo.dotStyle('dots' | 'rounded' | 'square') - Shape of QR code modules.cornerStyle('square' | 'rounded' | 'extra-rounded' | 'full-rounded' | 'maximum-rounded') - Shape of corner markers.
Returns
APromise resolving to an object:
url(URL) - Solana Pay URL (e.g.,solana:recipient?amount=10&spl-token=...)qr(string) - SVG markup of the QR code. Insert it withinnerHTML, or wrap it in a data URL (data:image/svg+xml;utf8,${encodeURIComponent(qr)}) to use it as an<img src>.