Skip to content
Commerce Kit is no longer maintainedCommerce Kit packages no longer receive updates or fixes. For new payment integrations, use Solana Pay.
The @solana-commerce/solana-pay package provides complete Solana Pay functionality for building payment experiences, compatible with the @solana/kit library. It handles URL encoding/parsing, QR code generation with custom styling, and transaction construction for both SOL and SPL token transfers.

​Installation

​URL Encoding

​encodeURL(fields)

Creates a Solana Pay URL that conforms to the Solana Pay specification. This function generates solana: protocol URLs that can be shared as links or encoded as QR codes for mobile wallets to scan.

​Parameters

  • fields (TransferRequestURLFields | TransactionRequestURLFields) - Configuration for the payment URL
The transfer request fields at a glance (details below):
ParameterTypeDescription
recipientAddressMerchant wallet address (required)
amountbigintAmount scaled by 1e9 (1 SOL = 1_000_000_000n), whatever the mint
splTokenAddressSPL token mint address (omit for SOL)
referenceAddress or Address[]Unique reference(s) for tracking payments
labelstringMerchant name shown in wallet
messagestringMessage shown before payment
memostringOnchain memo attached to transaction

​TransferRequestURLFields

Used for simple payment requests (direct transfers):
  • recipient (Address, required) - The merchant’s wallet address (base58-encoded public key) that will receive the payment. Can be a string or Address type from @solana/kit.
  • amount (bigint, optional) - Payment amount in lamports (atomic units). For SOL, 1 SOL = 1,000,000,000 lamports (9 decimals). encodeURL always divides by 1e9 when it writes the amount query parameter, whatever the token’s decimals (as of @solana-commerce/solana-pay@0.1.1). For a 6-decimal token such as USDC, pass the amount scaled to 9 decimals: 1 USDC = 1_000_000_000n, so 25 USDC = 25_000_000_000n. Passing the token’s atomic units (25_000_000n) produces amount=0.025, and the wallet requests 0.025 USDC. If you need a different scale, use encodeURL from @solana/pay, whose amount is a decimal number.
  • splToken (Address, optional) - The SPL token mint address for token payments. If omitted, the payment is assumed to be in SOL.
  • reference (Address | Address[], optional) - Unique reference address(es) used for tracking payments. Generate using generateKeyPairSigner().address. The reference is added as a read-only account to the transaction, allowing you to query for payments using this reference.
  • label (string, optional) - Human-readable merchant or app name displayed to the user in their wallet (e.g., “Coffee Shop”, “My Store”).
  • message (string, optional) - Message displayed to the user before payment (e.g., “Thanks for your purchase!”, “Tip for great service”).
  • memo (string, optional) - Onchain memo attached to the transaction. Stored permanently on Solana. Useful for order IDs, invoice numbers, or other payment metadata.

​TransactionRequestURLFields

Used for complex payment requests (including instructions):
  • link (URL, required) - The link to the transaction (Link). If the URL contains query parameters, it must be URL-encoded.
  • label (string, optional) - Human-readable merchant or app name displayed to the user in their wallet (e.g., “Coffee Shop”, “My Store”).
  • message (string, optional) - Message displayed to the user before payment (e.g., “Thanks for your purchase!”, “Tip for great service”).

​How It Works

The function performs several operations to construct a valid Solana Pay URL:
  1. Protocol Prefix - Creates a URL with the solana: protocol scheme (similar to mailto: or bitcoin:)
  2. Recipient as Pathname - Uses the recipient’s base58 address as the URL pathname (e.g., solana:merchantWalletAddress123...)
  3. Amount Conversion - Converts the bigint lamport amount to a decimal string representation without floating-point precision issues.
  4. Query Parameters - Appends all optional fields and references as URL-encoded query parameters

​Returns

URL object with the solana: protocol that can be:
  • Converted to a string with .toString() for sharing
  • Passed to createQR() for QR code generation
  • Used directly in anchor tags: <a href={url.toString()}>Pay with Solana</a>

​Example: Basic Payment

​Example: SPL Token Payment

​Example: Payment with Tracking

Use references to identify specific payments:

​URL Parsing

​parseURL(url)

Decodes and validates a Solana Pay URL, extracting all payment parameters. This function performs validation and converts amounts from decimal strings back to bigint lamports.

​Parameters

  • url (string | URL) - The Solana Pay URL to parse. Can be a string or URL object.

​Returns

A parsed TransferRequestURLFields or TransactionRequestURLFields object.

​Example: Parse and Validate

​Example: URL Validator Function


​QR Code Generation

​createQR(url, size, background, color)

Generates an SVG QR code optimized for Solana Pay URLs. The function produces styled, high-quality QR codes with rounded corners and customizable colors.

​Parameters

  • url (string | URL) - The Solana Pay URL to encode in the QR code
  • size (number, default: 512) - Width and height in pixels
  • background (string, default: 'white') - Background color (hex or named color). Should be light for wallet compatibility.
  • color (string, default: 'black') - Foreground/dot color (hex or named color). Should be dark for contrast.
Altenatively, you can use createStyledQRCode(url, options) for more control over the QR code styling (width, margin, colors, dot style, corner style, logo, logo size, logo background color, logo margin).

​Returns

Promise<string> - SVG markup as a string that can be:
  • Set as an img element src through a data URL: <img src={`data:image/svg+xml;utf8,${encodeURIComponent(qrCode)}`} />
  • Saved to a file

​Example

​Example: Branded QR Code

​Transaction Building

​createTransfer(rpc, sender, fields)

Builds a Solana transaction message for an SPL token payment transfer. It constructs the transfer, optional memo, and reference instructions, sets a blockhash lifetime from the RPC client and returns an unsigned transaction message (type TransactionMessageWithBlockhashLifetime, compatible with Solana Kit). You must set a fee payer before signing. In @solana-commerce/solana-pay@0.1.1 it builds a correct transfer only for Token-2022 mints (see the warning below).

​Parameters

  • rpc (Rpc<SolanaRpcApi>) - Solana RPC client from @solana/kit. Create with createSolanaRpc(rpcUrl).
  • sender (Address) - The payer’s wallet address. Must be a funded account that will sign the transaction.
  • fields (CreateTransferFields) - Transfer configuration:
    • recipient (Address, required) - Destination wallet address
    • amount (bigint, required) - Amount in lamports (SOL) or token atomic units (SPL)
    • splToken (Address, optional) - SPL token mint address. If omitted, creates SOL transfer.
    • reference (Address | Address[], optional) - Reference address(es) for tracking
    • memo (string, optional) - Onchain memo text

​Returns

Promise<TransactionMessageWithBlockhashLifetime> - Complete transaction message with:
  • Version 0 format (supports address lookup tables)
  • Blockhash lifetime (the transaction expires after 150 blocks, about 30 seconds at 200ms slots)
  • All necessary instructions (transfer + optional memo) for SPL token payments
  • No fee payer: call setTransactionMessageFeePayer (or setTransactionMessageFeePayerSigner) before signing and sending
As of @solana-commerce/solana-pay@0.1.1, createTransfer without splToken does not build a SOL transfer. It returns a single Token program Transfer instruction and silently drops memo and reference, so the transaction fails onchain with IncorrectProgramId. For SOL, build the instructions yourself (see the example below) or use createTransfer from @solana/pay.SPL token transfers are only correct for Token-2022 mints. For classic Token program mints such as USDC and USDT, createTransfer emits a Token-2022 TransferChecked instruction and the transaction fails with IncorrectProgramId. Build those transfers yourself (see the USDC example below).
createTransfer does not create the recipient’s associated token account. For an SPL token payment, the recipient’s token account for that mint must already exist before you send, or the transfer fails.

​Error Handling

Throws CreateTransferError with specific messages:
  • "sender not found" - Sender account doesn’t exist
  • "recipient not found" - Recipient account doesn’t exist

​Example: SOL Payment

Build the System program transfer, a memo, and the reference account yourself until createTransfer handles SOL correctly:
With a Kit client that has a payer and RPC plugins (Kit client), the same SOL payment is shorter, because the client sets the fee payer and lifetime and sends the transaction:

​Example: USDC Payment

USDC uses the classic Token program, so build the transferChecked instruction, the memo, and the reference account yourself. The recipient’s USDC token account must already exist: