What is Exact Payment?
The “exact payment” approach uses@faremeter/payment-solana/exact to give you complete control over the x402 payment flow on Solana. Unlike @faremeter/rides, which abstracts away the details, this approach lets you:
- Manually create and configure wallets
- Control network connections and RPC endpoints
- Choose specific payment tokens and mints
- Integrate custom wallet adapters (Ledger, Crossmint, Squads)
- Access the low-level x402 protocol
When to Use This Approach
Use exact payment when you need:- Custom wallet implementations
- Fine-grained control over payment configuration
- Integration with existing Solana infrastructure
- Multiple payment tokens or networks
@faremeter/rides when:
- You want the simplest possible integration (3 lines of code)
- You’re prototyping or building a quick demo
- You don’t need custom wallet logic
- Default payment configuration is sufficient
Full Example
This example shows how to make an x402-paid API call to Helius using the exact payment approach:Step-by-Step Breakdown
1. Token Lookup
lookupKnownSPLToken() function finds the correct USDC mint address for your network:
- mainnet-beta:
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v - devnet:
4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU
2. Wallet Creation
- Signs transactions using your private key
- Implements the x402 wallet protocol
- Can be swapped with other wallet adapters (Ledger, Crossmint, Squads)
3. Payment Handler
- Intercepts HTTP 402 (Payment Required) responses
- Reads the payment amount from the response
- Creates and signs a Solana SPL token transfer
- Submits the transaction to the network
- Retries the original request with payment proof
4. Fetch Wrapping
fetch() function to automatically handle x402 payments. You can add multiple handlers for different payment methods or networks.
Comparison: Exact vs Rides
- Exact: 40+ lines, full control, custom wallets
- Rides: 3 lines, fast setup, limited customization, great for demos
Related Resources
- Helius Examples - More complex API examples
- @faremeter/rides Overview - Quick start approach
- Package Reference - API documentation
- Custom Wallets - Wallet integration guide