@faremeter/payment-solana
@faremeter/payment-solana brings Coinbase’s x402 exact scheme to Solana. It includes:
Source: GitHub › packages/payment-solana
- A wallet-side payment handler that builds and signs SPL-token transfer transactions.
- A facilitator handler that validates transactions, signs as fee payer, and broadcasts them.
- Runtime validators and matchers for guarding request payloads.
@faremeter/fetch and @faremeter/facilitator to orchestrate non-custodial USDC payments on Solana.
Quick start
Modules
exact/createPaymentHandler(wallet, mint, connection?, options?)
Returns a PaymentHandler for the client.
wallet: object with{ network, publicKey }plus optionalbuildTransaction,updateTransaction,sendTransaction. Matches the shape produced by@faremeter/wallet-solana,@faremeter/wallet-crossmint, or custom implementations.mint: SPL token mintPublicKey.connection: optionalConnection. Required to auto-fetch blockhashes and mint decimals unless the facilitator provides them via the requirementsextrafield.options.token: advanced config forwarded togetAssociatedTokenAddressSync(e.g.,allowOwnerOffCurve).
- Validates the
extrapayload usingPaymentRequirementsExtra(fee payer, decimals, blockhash). - Builds compute budget and
transferCheckedinstructions sending the fullmaxAmountRequiredto the merchant. - Uses wallet hooks (
buildTransaction,updateTransaction,sendTransaction) to customize signing/broadcasting. - Returns payload
{ transaction: base64EncodedWireTransaction }.
exact/createFacilitatorHandler(network, rpc, feePayerKeypair, mint, config?)
Creates a FacilitatorHandler for the server side.
network:"devnet" | "testnet" | "mainnet-beta"(or custom cluster names recognized by@faremeter/info/solana).rpc: Solana RPC client compatible with@solana/kit.feePayerKeypair: payer authority that signs outgoing transactions.mint: USDC mintPublicKey.config.maxRetries(default30): how many times to poll confirmation.config.retryDelayMs(default1000): delay between status checks.config.maxPriorityFee(lamports): upper bound for priority fee; mismatches reject the transaction.
getSupported: advertises x402 networks returned bylookupX402Network(network)with fee payer info inextra.getRequirements: filters and enriches requirements withasset,recentBlockhash,decimals, andfeePayer.handleSettle: validates the incoming base64 transaction, ensures it matches the expected transfer, partially signs with the fee payer, simulates & sends, and polls confirmation.
{ success: false, error } to prompt the client to retry.
Validators & helpers
PaymentRequirementsExtra: arktype schema ensuringfeePayer, optionaldecimals,recentBlockhash.PaymentPayload: arktype schema for{ transaction: base64EncodedWireTransaction }.isValidTransaction(transactionMessage, requirements, facilitatorPublicKey, maxPriorityFee?): asserts the transaction instructions match the expected compute budget + transfer (and optional ATA creation).generateMatcher(network, asset): builds a requirements matcher usinglookupX402Network(network)and the mint address.x402Scheme: exported literal"exact".logger: Logtape logger under["faremeter","payment-solana"].
Usage patterns
- Managed wallets: Pass wallets from
@faremeter/wallet-crossmintor a custodial provider. As long as they exposenetwork,publicKey, and anupdateTransactionorsendTransactionhook, the handler works. - Cold wallets: For air-gapped flows, provide
buildTransactionto write instructions to disk, have the user sign offline, then return the signed transaction throughupdateTransaction. - Priority fees: Set
maxPriorityFeeto avoid draining SOL from payers if competing transactions spike the compute budget price. - Observability: Facilitator logs helpful context when validation fails (e.g., mismatched destination). Capture
["faremeter","payment-solana"]logs.
Related references
@faremeter/info/solana: registries for clusters and assets, pluslookupX402Network.@faremeter/middleware&@faremeter/fetch: orchestrate the HTTP 402 handshake using these handlers.@faremeter/wallet-*: wallet adapters that return the requiredwalletshape.