TypeScript Solana Pay SDK
The TypeScript Solana Pay SDK, published as @solana/pay, helps merchants and wallets use one Solana payment flow. It turns payment intent into a standard URL, turns that URL into a wallet action, and lets the merchant find and check the resulting on-chain transfer.
System model
The SDK supports two actors with different duties. A merchant creates a request and reads the network. A wallet reads the request, creates the transfer, asks the customer to approve it, and sends it.
Merchant and wallet roles
The merchant side does not need a signer. It uses an RPC connection to publish a request, display it, and inspect payment activity. The wallet side needs a payer signer because it must create and send a transaction for the customer.
| Role | Main outcome | Client entry point |
|---|---|---|
| Merchant | A payment request that can be displayed and checked | createMerchantClient |
| Wallet | A customer-approved transfer sent to Solana | createWalletClient |
| Combined application | Both sets of capabilities in one client | createSolanaPayClient |
The SDK groups these capabilities under the pay namespace. This keeps payment actions separate from the shared RPC, signer, and transaction services that the client uses. The merchant namespace also supports real-time reference watching when the client has an RPC subscription service.
References: typescript/…/merchant.ts• L51-70 typescript/…/wallet.ts• L23-33 typescript/…/watchReference.ts• L24-35
Payment request types
Solana Pay has two request types. A transfer request states the recipient and payment fields so a wallet can compose a standard SOL or SPL token transfer. A transaction request carries an HTTPS link so the wallet can ask a merchant service for a transaction made for that customer.
| Request | Merchant publishes | Wallet performs |
|---|---|---|
| Transfer request | Recipient, optional amount, token, references, and display text | Parses the fields and creates transfer instructions |
| Transaction request | An HTTPS link with optional display text | Fetches a base64 transaction from the link and checks it before signing |
Read Solana Pay transaction URLs for the URL forms and request roles. Read Solana Pay transfer primitives for the transfer fields and on-chain meaning.
References: typescript/…/encodeURL.ts• L5-35 typescript/…/parseURL.ts• L6-35 typescript/…/fetchTransaction.ts• L37-51 typescript/…/OVERVIEW.md• L73-84
Payment lifecycle
The SDK connects checkout state to a payment on Solana. The merchant creates trusted order data first, the wallet sends the customer’s payment, and the merchant checks both the transaction identity and its transfer effect before completing the order.
Request creation and display
The merchant creates a unique reference for the checkout and keeps the expected amount in a trusted service. encodeURL produces the solana: request URL. createQR turns that URL into a QR code that a wallet can scan. The merchant can also use createQROptions when it needs to pass the QR data to another renderer.
The reference links the customer session to the later chain search. The label, message, and memo add context for the wallet or the transaction record. The merchant can request native SOL by omitting splToken, or request an SPL token by supplying its mint address.
References: typescript/…/encodeURL.ts• L64-103 typescript/…/createQR.ts• L20-38 typescript/…/merchant.ts• L87-95 typescript/…/simulateCheckout.ts• L4-25 typescript/…/MERCHANT_INTEGRATION.md• L65-143
Wallet transfer
The wallet parses the URL and shows the request context to the customer. It then creates instructions that match the requested asset and amount. The wallet client supplies the payer and the transaction services needed to sign, submit, and confirm the transfer.
The same path supports native SOL and SPL tokens. The SDK checks the account and mint state that it needs before it creates instructions. It also preserves references on the transfer and places a requested memo in the transaction flow. A wallet can provide a sender for one transfer or use the client’s configured payer.
References: typescript/…/wallet.ts• L23-42 typescript/…/wallet.ts• L50-65 typescript/…/createTransfer.ts• L28-81 typescript/…/WALLET_INTEGRATION.md• L20-129
Payment discovery and validation
After the wallet sends the transaction, the merchant uses the reference to locate a candidate signature. findReference searches through confirmed address activity by HTTP polling and returns the oldest matching result, while watchReference listens for a matching log notification over WebSocket and returns when one arrives.
A found signature only proves that a transaction mentioned the reference. validateTransfer is the trust boundary for order fulfillment. It checks the transaction result, transfer destination, requested asset, reference accounts, balance change, and optional memo before the merchant marks the order as paid. It accepts legacy, version 0, and version 1 transactions. For version 0 transactions that use address lookup tables, the RPC response must include complete loaded writable and read-only address lists so the SDK can resolve the transfer accounts safely.
Validation also rejects invalid payment inputs before it reads the transaction. The requested amount must be finite and non-negative. For native SOL, the final instruction must be a system-program SOL transfer to the expected recipient. For SPL tokens, the final instruction must be a supported token transfer to the recipient’s associated token account, and a checked transfer must name the expected mint. The recipient balance must increase by at least the requested base-unit amount. A token account created in the payment transaction starts from zero when no pre-transaction token balance exists. When a memo is required, the preceding instruction must contain the expected text under a supported memo program, including the legacy and v4 memo programs.
The diagram shows how a checkout request becomes a validated payment.
flowchart LR
A[Trusted checkout data] --> B[Encode transfer URL]
B --> C[Display URL or QR code]
C --> D[Wallet parses request]
D --> E[Wallet creates and sends transfer]
E --> F[Reference search or WebSocket watch]
F --> G[Validate signature and transfer]
G --> H[Complete order]
Use Solana Pay merchant examples for a runnable flow that follows these stages.
References: typescript/…/findReference.ts• L35-71 typescript/…/watchReference.ts• L24-73 typescript/…/validateTransfer.ts• L74-169 typescript/…/validateTransfer.ts• L171-291 typescript/…/validateTransfer.test.ts• L121-497 typescript/…/transactionVersions.test.ts• L92-117 typescript/…/validateTransferLookupTables.test.ts• L124-180 typescript/…/main.ts• L26-77
Transaction requests
Transaction requests extend the payment flow when a merchant must choose the full transaction. The wallet sends the customer account to the merchant’s HTTPS endpoint. The endpoint returns a base64 transaction, and the wallet prepares it for the customer account when needed.
This path can represent a payment or another merchant-directed Solana action. The merchant must calculate order values on the server and return a transaction that the wallet can decode and verify. Read Solana Pay transaction URLs for the request contract and server flow.
Merchant transaction responses
The merchant can use buildTransaction to assemble instructions with a fee payer and return the serialized result. It builds version 0 by default and can build a version 1 transaction with message-level resource and fee settings. The wallet’s fetchTransaction method sends the account to the HTTPS link, accepts the transaction response, and rejects a response that is not a usable transaction.
Version 1 needs an explicit compute unit limit because a missing limit gives the transaction zero compute units. The target Solana cluster must also support the version 1 feature gate. Legacy and version 0 transactions remain supported.
The transaction request endpoint is therefore a boundary between a merchant service and a wallet. The endpoint chooses the action. The wallet controls customer approval and signing.
References: typescript/…/merchant.ts• L38-49 typescript/…/merchant.ts• L105-129 typescript/…/fetchTransaction.ts• L37-77 typescript/…/transactionVersions.test.ts• L119-150 typescript/…/MERCHANT_INTEGRATION.md• L40-117
SDK boundaries
The SDK relies on the Solana RPC service for account state, transaction records, and address history. It uses an RPC subscription service only when the merchant chooses real-time reference observation. The SDK does not decide when an order is shipped; the merchant application owns that state after validation succeeds.
Client selection
Choose the smallest client that has the required authority. A merchant client avoids customer signing keys. A wallet client includes a payer and transaction sending. A combined client is useful only when one process must perform both roles.
| Need | Client |
|---|---|
| Create and display requests; find, watch, or validate payments | Merchant |
| Parse requests; create and send customer transfers; fetch transaction requests | Wallet |
| Run both flows in one trusted process | Combined |
Each client accepts an RPC URL. A merchant that uses watchReference also needs an RPC subscription configuration. The published @solana/pay package is version 1.2.0, requires Node.js 20 or later, uses @solana/kit 8.6 or later, supports legacy through version 1 transactions, and supports both import and require consumers. Transfer creation and validation also use the Solana system, token, token-2022, and memo program packages as peer dependencies. The package exposes the pay command for its supported platform artifacts.
References: typescript/…/client.ts• L9-18 typescript/…/client.ts• L43-50 typescript/…/client.ts• L82-89 typescript/…/merchant.ts• L80-103 typescript/…/wallet.ts• L43-65 typescript/…/package.json• L1-100 typescript/…/README.md• L3-10
Network finality
Discovery and validation use a commitment level to state how much network confirmation the merchant requires. confirmed is the default for reference watching and transfer validation. finalized gives a stronger finality level but can delay order completion.
The merchant must apply the same business rule to discovery and validation. A notification with an error can identify a failed transaction, and a signature found by discovery still requires transfer validation. Reference watching ends when it receives a matching notification or when its abort signal cancels the subscription.
References: typescript/…/types.ts• L30-31 typescript/…/findReference.ts• L13-23 typescript/…/watchReference.ts• L8-14 typescript/…/watchReference.ts• L42-73 typescript/…/validateTransfer.ts• L131-169
Change checklist
When these files or sections are changed, remember to consider these:
- Keep transfer URL fields aligned across
encodeURL,parseURL, wallet instruction creation, and merchant validation. A field that is accepted in only part of this path can create an intent that the wallet and merchant interpret differently. - Keep each checkout reference unique and tied to the server-side expected amount. Discovery and validation both depend on that association.
- Preserve the native SOL versus SPL token split when changing amount rules. Token mint decimals and the recipient token account affect both instruction creation and balance validation.
- Keep the merchant and wallet client capabilities matched to their RPC, signer, and subscription requirements. Adding reference watching requires an RPC subscription service.
- Keep transaction request responses compatible with the wallet fetch boundary: the endpoint must return a decodable base64 transaction for the account supplied by the wallet.
- Keep transaction version rules aligned between merchant transaction building, wallet transaction fetching, and transfer validation. Version 1 builders need a compute unit limit and a compatible target cluster.
- Keep version 0 lookup-table responses aligned with the transaction message. The RPC response must include the expected loaded writable and read-only addresses or validation must reject the payment.
- Keep validation’s last-instruction rule and optional memo position aligned with wallet transfer creation. A new instruction order can make a valid payment fail closed.
- Keep the set of accepted memo program addresses aligned with memo creation and validation. A memo from an unsupported program must not pass as proof of payment.
- Keep native and token balance metadata tied to the recipient account. A new token account has no pre-balance entry, but it still needs a valid post-balance entry.
- Review commitment and abort behavior when changing payment status handling. A faster observation result must not bypass transfer validation or leave a live subscription running.
- Keep the package runtime, peer dependencies, import and require entry points, and supported command artifacts aligned when changing the published package boundary.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A URL uses an invalid protocol, recipient, amount, token, or reference | The wallet cannot form a trusted request | Parse the URL before using its fields and handle ParseURLError |
| A reference is reused across checkout sessions | Discovery can return a transaction for the wrong order | Generate and store one reference with each pending checkout |
The requested amount is negative, NaN, or infinite | Validation stops before it can assess the transaction | Reject invalid amounts and store finite checkout values |
| Discovery returns a signature for a failed or wrong transfer | The merchant may record payment without receiving the expected asset | Run validateTransfer with the stored recipient, amount, token, reference, and memo |
| The last instruction is not the expected SOL or token transfer | Validation rejects the transaction even if another instruction moved funds | Require the wallet to preserve the expected transfer as the final instruction |
| A version 0 transaction uses address lookup tables but the RPC response omits or truncates loaded addresses | The SDK cannot safely resolve transfer accounts and rejects validation | Request transaction data with loaded address metadata and treat ValidateTransferError as an invalid payment |
| Token balance metadata is missing or has no recipient post-balance | The SDK cannot prove the requested token increase | Return complete recipient token balance metadata from RPC |
| A required memo is missing, has the wrong text, or uses an unsupported memo program | Validation rejects the payment | Put the expected memo immediately before the transfer and use a supported memo program |
| A wallet lacks funds or a usable token account | Transfer instruction creation or submission fails | Check the payer and token account state before asking the customer to approve |
| A watcher is aborted before a notification arrives | The merchant receives no payment result | Treat the abort as an incomplete observation and retry or close the checkout |
| A transaction request endpoint returns bad JSON, base64, or wire data | The wallet cannot prepare the merchant-selected transaction | Return a valid serialized transaction and handle FetchTransactionError |
| A version 1 transaction has no compute unit limit or the cluster lacks its feature gate | The transaction can fail or cannot run on the target cluster | Set a compute unit limit and confirm version 1 support before using it |
| A consumer runs the package on an unsupported Node.js version | The SDK may fail before the payment flow starts | Use Node.js 20 or later |
Key files
| File | Why to read it |
|---|---|
| typescript/…/client.ts | Defines the merchant, wallet, and combined client roles. |
| typescript/…/merchant.ts | Connects merchant actions to URL creation, QR display, discovery, validation, reference watching, and transaction assembly. |
| typescript/…/wallet.ts | Connects wallet actions to URL parsing, transfer creation, and transaction requests. |
| typescript/…/encodeURL.ts and parseURL.ts | Define the two Solana Pay URL directions: creating a request and reading one. |
| typescript/…/createTransfer.ts | Shows the wallet-side boundary for native SOL and SPL token transfers. |
| typescript/…/findReference.ts, watchReference.ts, and validateTransfer.ts | Show how a merchant discovers or observes a candidate transaction and checks its payment effect. |
| typescript/…/validateTransfer.test.ts | Shows validation of SOL and SPL transfers, references, memos from supported memo programs, balance changes, and malformed transaction data. |
| typescript/…/validateTransferLookupTables.test.ts | Shows validation of native and token transfers when version 0 transactions load recipients or references through address lookup tables. |
| typescript/…/fetchTransaction.ts | Defines the wallet boundary for merchant-provided transaction requests. |
| typescript/…/createQR.ts | Defines the QR representation used to present a payment URL. |
| typescript/…/package.json | Defines the published package boundary, runtime requirement, peer dependencies, module entry points, command entry point, and supported platform artifacts. |
| typescript/…/transactionVersions.test.ts | Shows the supported transaction versions for validation and transaction-request handling. |
| typescript/…/integration.test.ts | Shows end-to-end URL, SOL, SPL token, memo, reference, and transfer failure behavior in a local Solana runtime. |
| typescript/…/main.ts | Runs the complete merchant-to-wallet-to-validation flow. |
| typescript/…/README.md | Describes a runnable QR-based in-person payment example. |