Introducing a new way to review your PRs.

Read the announcement

solana-foundation / pay

CLI for Agentic payments (x402, MPP, AP2).

View on GitHub

30 documents · Updated Nov 11, 2026

docs / solana-pay-transfer-primitives

Solana Pay transfer primitives

The Solana Pay transfer primitives define the shared contract between a merchant and a wallet. They turn payment intent into a solana: URL, let a wallet build a native SOL or SPL token transfer, and let a merchant find and verify the payment on Solana. This page is a focused companion to TypeScript Solana Pay SDK and Solana Pay merchant examples.

Request model

Solana Pay uses two URL forms for two different levels of control. A transfer request contains enough data for a wallet to build a standard payment. A transaction request points to an HTTPS service that builds a wider range of transactions for the wallet.

URL forms

The SDK represents both forms through encodeURL and parseURL. Transfer URLs name a recipient in the path. Transaction URLs carry an HTTPS link in the path and may include display text for the wallet.

URL formPurposeMain wallet action
Transfer requestRequest a direct SOL or SPL token paymentParse fields and create transfer instructions
Transaction requestRequest a merchant-defined Solana transactionSend the wallet account to the HTTPS link and prepare its transaction response

Transfer request fields use user-facing amounts. The token mint selects an SPL token; when it is absent, the request means native SOL. label and message give the customer context. memo becomes public transaction data. reference values identify the payment for later discovery.

The parser rejects malformed protocol, address, amount, token, reference, and transaction-link values. It returns optional fields as absent values so the wallet can decide how to handle an omitted amount. References: typescript/…/parseURL.ts• L6-16, typescript/…/parseURL.ts• L18-36, typescript/…/parseURL.ts• L38-62, typescript/…/parseURL.ts• L64-128, typescript/…/types.ts• L3-45

URL encoding

encodeURL is the merchant-side counterpart to parsing. It preserves the Solana Pay scheme and places optional transfer fields in query parameters. It accepts one reference or many and emits each reference in its original order.

Transaction links receive conditional URL encoding. A link with query data is encoded so its parameters do not conflict with Solana Pay parameters. A link without query data stays shorter, which helps when the URL is shown as a QR code.

The encoded URL is a payment request, not proof of payment. Merchants must create sensitive order values and references in a trusted service before they display it. References: typescript/…/encodeURL.ts• L5-43, typescript/…/encodeURL.ts• L46-61, typescript/…/encodeURL.ts• L64-103, typescript/…/reference.ts• L3-10, typescript/…/MERCHANT_INTEGRATION.md• L65-105

Transfer construction

Transfer construction converts trusted request fields into instructions that a wallet can place in a transaction. The wallet supplies the sender and RPC access. The result contains the memo before the asset transfer when a memo is requested, and carries references as read-only accounts on the transfer instruction.

Native SOL transfers

A native SOL request uses the system transfer path. The SDK checks that the sender is a usable native account and that an existing recipient is also a usable native account. A recipient account may be absent because the system transfer can create it.

The requested SOL amount must fit within SOL precision and the sender must have enough lamports. The SDK then converts the user amount to base units before it creates the transfer instruction. References remain attached to that instruction so Solana address indexing can find the payment later. References: typescript/…/createTransfer.ts• L47-81, typescript/…/createTransfer.ts• L84-121, typescript/…/amount.ts• L1-30

SPL token transfers

An SPL token request uses the mint in splToken to select the asset and its precision. The SDK derives the sender and recipient associated token accounts from the wallet addresses and mint. It checks the mint and token accounts before creating a checked token transfer.

The transfer requires usable token accounts with enough base units. The recipient is the wallet address represented by its associated token account, not an auxiliary token account. The token program can be the classic token program or Token-2022 when the mint belongs to that program. References and an optional memo follow the same request rules as a SOL transfer. References: typescript/…/createTransfer.ts• L124-181, typescript/…/types.ts• L33-45, typescript/…/SPEC.md• L48-60

Wallet approval

Instruction creation does not approve or send money. The wallet must show the request context and ask the customer to approve the transaction. A wallet client then supplies signing, recent blockhash, submission, and confirmation services around the instructions.

The wallet should treat request data as untrusted input. In particular, label, message, and memo provide context but do not replace checks on the recipient, asset, amount, and references. References: typescript/…/wallet.ts• L23-69, typescript/…/client.ts• L42-80, typescript/…/WALLET_INTEGRATION.md• L104-142

Payment discovery

References provide a link between a checkout session and a future chain record. A merchant creates a reference before the wallet sends the payment, includes it in the request, and uses it to locate candidate transaction signatures after the payment is submitted.

findReference uses address history to search for transactions that mention one reference. It returns the oldest matching signature in the available history and continues through older pages when the result limit is full. It uses confirmed-or-stronger commitment levels rather than processed state.

watchReference provides the real-time alternative. It subscribes to log notifications that mention the reference and returns the first notification. An abort signal stops the wait, so the merchant can close or retry an incomplete checkout. References: typescript/…/findReference.ts• L13-71, typescript/…/watchReference.ts• L8-73, typescript/…/types.ts• L30-31

Transfer validation

Discovery only proves that a transaction mentioned the reference. validateTransfer is the payment check that decides whether the transaction satisfies the checkout request. It also rejects invalid requested amounts and transaction data that cannot be decoded safely.

Validation checks the transaction result and its final transfer instruction. It confirms the expected recipient and asset, checks reference accounts and their order, and compares the recipient balance change with the requested amount. For versioned transactions, it also checks that address-table data is present and matches the transaction. When a memo was requested, it checks the memo instruction immediately before the transfer. It supports native SOL and both supported SPL token program balance records.

The merchant should use the recipient, amount, token, references, and memo saved for the checkout. It should release goods or services only after validation succeeds. References: typescript/…/validateTransfer.ts• L42-47, typescript/…/validateTransfer.ts• L74-105, typescript/…/validateTransfer.ts• L131-168, typescript/…/validateTransfer.ts• L171-200, typescript/…/validateTransfer.ts• L202-290, typescript/…/MERCHANT_INTEGRATION.md• L297-334

Transaction requests

Transaction requests let a merchant choose the full transaction instead of asking the wallet to create only a standard transfer. The wallet sends the account that may sign to the merchant's HTTPS link, and the link returns a base64-encoded serialized transaction.

Transaction fetching

fetchTransaction treats the HTTP response and transaction as untrusted. It requires a successful response with a valid JSON transaction field, decodes the transaction, and checks its wire data before returning it.

An unsigned response receives the wallet account as fee payer and a fresh blockhash. A response with signatures keeps its transaction setup only when the signatures are valid and no unexpected signer is required. If only the wallet account still needs to sign, the SDK can refresh an expired blockhash. References: typescript/…/fetchTransaction.ts• L24-51, typescript/…/fetchTransaction.ts• L52-100, typescript/…/fetchTransaction.ts• L102-158, typescript/…/SPEC.md• L139-189

Merchant transaction assembly

The merchant plugin can assemble instructions with a fee payer and return the serialized transaction for a transaction request endpoint. It supports version 0 and version 1 messages. Version 1 can carry message resource limits and a priority fee through its config.

This path is broader than transfer requests. It can support a merchant-defined Solana action, so the wallet must inspect the transaction before it asks the customer to sign. References: typescript/…/merchant.ts• L38-49, typescript/…/merchant.ts• L64-70, typescript/…/merchant.ts• L105-128, typescript/…/MERCHANT_INTEGRATION.md• L40-117

QR presentation

QR generation turns a Solana Pay URL into a scannable payment surface. createQR accepts the URL and produces a styled QR object that a merchant page can append to a display element.

The default presentation uses a light background, a dark foreground, a margin, and error correction suited to device scanning. Merchants can request a different size or colors, but the QR must remain easy for a wallet camera to read. The QR output uses SVG data and includes Solana branding without changing the payment URL. References: typescript/…/createQR.ts• L20-35, typescript/…/createQR.ts• L37-61, typescript/…/MERCHANT_INTEGRATION.md• L145-197

Client plugins

The SDK exposes these primitives through plugins that add a pay namespace to a Solana client. The plugins keep merchant read operations separate from wallet operations that need a payer signer.

Merchant plugin

The merchant plugin provides URL encoding, QR creation, reference discovery, WebSocket reference watching, transfer validation, and transaction assembly. It needs RPC access for address history and transaction data. Reference watching also needs RPC subscriptions. It does not need a payer signer.

Use createMerchantClient when one process creates requests and checks payments. The plugin also preserves an existing pay namespace when it adds these methods. References: typescript/…/merchant.ts• L23-36, typescript/…/merchant.ts• L51-70, typescript/…/merchant.ts• L80-103, typescript/…/merchant.ts• L105-132, typescript/…/client.ts• L9-40

Wallet plugin

The wallet plugin provides URL parsing, transfer instruction creation, and transaction request fetching. It needs RPC access for account and blockhash data. Transfer creation uses an explicit sender when supplied or the client's configured payer.

Use createWalletClient when the process represents a wallet that can sign and send a customer's transaction. A combined client can install both plugins when one trusted process must perform both roles. The wallet plugin also preserves an existing pay namespace while adding its methods. References: typescript/…/wallet.ts• L19-33, typescript/…/wallet.ts• L36-42, typescript/…/wallet.ts• L43-69, typescript/…/client.ts• L42-80, typescript/…/client.ts• L82-119, typescript/…/index.ts• L1-13

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the transfer field contract aligned across URL encoding, URL parsing, instruction creation, and validation. A field that crosses only part of this path can change the payment intent.
  • Preserve the distinction between a native SOL recipient and an SPL token recipient account. The mint and token program determine the associated account and balance data used by both creation and validation.
  • Keep reference order and checkout ownership stable. Discovery can find a transaction, but validation depends on the reference and expected values saved for the same checkout.
  • Keep memo placement consistent with validation. A requested memo must remain directly before the transfer instruction.
  • Keep transaction decoding compatible with validation. Versioned transactions must provide loaded addresses that match their address-table lookups.
  • Keep transaction request responses compatible with the wallet boundary. The response must contain a decodable serialized transaction and must not require an unexpected signer.
  • Keep plugin requirements matched to client setup. Reference watching needs subscriptions, while transfer creation needs a payer or explicit sender.
  • Keep merchant transaction version and config rules aligned. Version 1 resource settings are not valid for version 0 messages.

Important failure modes

TriggerConsequenceGuard
A request has unsupported precision or invalid address fieldsThe wallet cannot create a valid transferParse the URL and handle ParseURLError or CreateTransferError
A wallet has no usable native account or token accountInstruction creation fails or the transfer cannot settleCheck account, mint, associated account, state, and balance errors before approval
A reference is reused or is not tied to server-side order dataDiscovery can identify the wrong checkoutGenerate and store a reference for each pending checkout
A found transaction mentions the reference but sends the wrong asset or amountThe merchant can mark an unpaid order as paidRun validateTransfer with the stored transfer fields
A versioned transaction has missing or mismatched loaded addressesValidation rejects an otherwise parseable transactionReturn complete address-table data with the transaction response
A transaction request has invalid JSON, base64, wire data, or signaturesThe wallet cannot safely prepare or sign the transactionTreat the response as untrusted and handle FetchTransactionError
A reference watch is aborted before a notificationThe merchant receives no payment resultTreat the checkout as pending and retry or close it
A QR code has poor contrast or too little spaceWallet cameras may fail to scan the requestKeep a light background, dark data, and enough size and margin
Version 1 transaction settings are passed to a version 0 buildMerchant transaction assembly fails before it reaches the walletPass config only with version 1

Key files

FileWhy to read it
typescript/…/types.tsDefines the shared transfer fields and request value types.
typescript/…/parseURL.ts and encodeURL.tsDefine how transfer and transaction requests cross the URL boundary.
typescript/…/createTransfer.tsShows the wallet-side creation boundary for SOL and SPL token payments.
typescript/…/validateTransfer.tsDefines the merchant-side checks that turn a candidate signature into a valid payment.
typescript/…/findReference.ts and watchReference.tsDefine HTTP history search and WebSocket discovery of reference activity.
typescript/…/fetchTransaction.tsDefines the wallet boundary for merchant-provided transaction requests.
typescript/…/createQR.tsDefines the URL-to-QR presentation boundary.
typescript/…/merchant.ts and plugins/wallet.tsShow how the primitives become merchant and wallet pay capabilities.
typescript/…/client.tsShows the client choices and the RPC, signer, and subscription needs for each role.
typescript/…/SPEC.mdDefines the protocol meaning of transfer fields, references, and transaction requests.