Solana Processor
The SolanaPaymentProcessor handles all Solana blockchain operations for X402 payments.
Overview
The processor handles:
Creating payment transactions
Signing and broadcasting transactions
Verifying payments on-chain
Getting token balances
Managing associated token accounts
Creating a Processor
import { SolanaPaymentProcessor } from '@shade402/core';
import { Keypair } from '@solana/web3.js';
const processor = new SolanaPaymentProcessor(
'https://api.devnet.solana.com',
walletKeypair, // Optional: for signing
{
defaultDecimals: 6, // Default token decimals
memo: 'X402 payment', // Optional memo
}
);Creating Payment Transactions
The processor:
Validates the payment request
Checks expiration
Validates amount doesn't exceed maximum
Creates associated token accounts if needed
Creates transfer instruction
Adds memo instruction if provided
Signing and Broadcasting
Verifying Payments
Verify that a payment transaction exists and is valid on-chain:
Verification checks:
Transaction exists on blockchain
Transaction signature is valid
Transaction is confirmed
Payment details match
Getting Token Balance
Associated Token Accounts
The processor automatically handles associated token accounts:
Creates payer's token account if it doesn't exist
Creates recipient's token account if it doesn't exist
Pays for account creation fees
Complete Example
Error Handling
The processor throws specific errors:
Configuration Options
Cleanup
Always close the processor to cleanup connections:
Best Practices
Reuse processor instance for multiple transactions
Always close processor when done
Handle errors appropriately
Check balance before creating transaction
Use appropriate RPC endpoint for network
Monitor transaction status
Retry failed transactions
Next Steps
Learn about Payment Models
Check out Core Package overview
See Examples for usage
Last updated
