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

  1. Reuse processor instance for multiple transactions

  2. Always close processor when done

  3. Handle errors appropriately

  4. Check balance before creating transaction

  5. Use appropriate RPC endpoint for network

  6. Monitor transaction status

  7. Retry failed transactions

Next Steps

Last updated