Overview
The Solana payment handler implements theexact scheme for x402-exact payments on Solana-based networks (Mainnet, Devnet, Testnet). It uses partially-signed transactions where the client and facilitator co-sign a single transaction.
Supported Networks
- solana-mainnet-beta - Solana Mainnet Beta
- solana-devnet - Solana Devnet
- solana-testnet - Solana Testnet
Payment Mechanism
Partially-Signed Transactions
In Solana x402-exact payments:- Client creates transaction: Builds a transaction that transfers SPL tokens from their wallet to the merchant
- Client signs partially: Signs the transaction with their wallet key
- Facilitator co-signs: Adds its signature as the fee payer
- Facilitator submits: Sends the fully-signed transaction to Solana
Fee Payer Role
The facilitator acts as the fee payer for all Solana transactions:- Pays network transaction fees (varies by network conditions)
- Pays priority fees if specified in the transaction
- Must maintain a SOL balance to cover fees
Requirements Enrichment
When a resource server calls/accepts, the Solana handler adds these fields to the extra object:
The facilitator’s public key that will co-sign as fee payer.Example:
"9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"Token decimals for the specified asset mint. Used for amount calculations.Example:
6 for USDCRecent blockhash for transaction validity. Transactions are only valid for ~60 seconds.Example:
"4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ..."Settlement Validation
When processing a/settle request, the Solana handler performs extensive validation:
1. Fee Payer Verification
Ensures the transaction’s fee payer matches the facilitator’s public key:2. Compute Budget Validation
Validates maximum priority fee to prevent excessive costs:- Maximum priority fee ≤ 100,000 lamports (configurable)
- Priority fee is calculated as: (compute units × price in micro-lamports) / 1,000,000
3. Transfer Instruction Validation
Verifies the SPL token transfer instruction:4. Security Checks
Prevents facilitator fund theft:- Ensures source token account is NOT owned by facilitator
- Verifies no other instructions attempt to drain facilitator accounts
- Checks authority fields point to client, not facilitator
Transaction Execution
After validation, the facilitator:- Signs transaction: Adds facilitator signature as fee payer
- Simulates transaction: Validates transaction will succeed on-chain
- Submits to RPC: Sends transaction to Solana network
- Polls for confirmation: Checks transaction status until confirmed or finalized
- Returns result: Provides transaction signature and network ID
Token Support
The Solana handler supports any SPL token, including:- USDC:
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v(Mainnet) - Custom tokens: Any SPL token mint address
Error Scenarios
Common errors during Solana payment processing:| Error | Cause | Solution |
|---|---|---|
| Fee payer mismatch | Transaction fee payer isn’t facilitator | Client must use facilitator’s feePayer from requirements |
| Invalid transfer amount | Amount doesn’t match requirements | Verify amount calculation matches token decimals |
| Transaction simulation failed | Transaction would fail on-chain | Check token accounts exist and have sufficient balance |
| Blockhash expired | Recent blockhash too old (>60s) | Client must fetch fresh requirements before payment |
| Compute budget exceeded | Compute units or priority fee too high | Reduce compute limits to reasonable values |