SettlementAgent
TheSettlementAgent is the core class for creating agents that can send x402 payments on Solana. It supports both USDC and ATHR tokens.
Supported Tokens
| Token | Mint Address (Mainnet) | Decimals | Description |
|---|---|---|---|
| ATHR | 5abiPeWqRLYb21DWNGYRFwrABML24dYuGn39ZpPYpump | 6 | Native Aether token |
| USDC | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v | 6 | USD Coin stablecoin |
Constructor
| Parameter | Type | Description |
|---|---|---|
merchantWallet | string (optional) | Default recipient wallet for payments |
MERCHANT_WALLET_ADDRESS in environment variables.
Methods
init()
Initialize the agent with a wallet.| Parameter | Type | Description |
|---|---|---|
wallet | Keypair (optional) | Solana keypair. If not provided, loads from env |
setMerchantWallet()
Set the recipient wallet dynamically.createSignedPayment()
Create a signed x402 payment that can be submitted by the recipient. Supports both ATHR and USDC tokens.| Parameter | Type | Description |
|---|---|---|
recipientAddress | string | Solana wallet address of recipient |
amount | number | Amount in tokens (e.g., 1.00 for 1 token) |
options | PaymentOptions (optional) | Payment options including token type |
PaymentOptions
| Option | Type | Default | Description |
|---|---|---|---|
token | 'athr' | 'usdc' | 'usdc' | Token to use for payment |
triggerSettlement()
Execute a settlement flow (internal use).Token Utilities
The SDK exports utility functions for working with tokens:Payment Payload Structure
The x402 payment header contains:asset field contains the token mint address (ATHR or USDC).
Environment Variables
| Variable | Description | Required |
|---|---|---|
SOLANA_NETWORK | devnet or mainnet-beta | Yes |
SOLANA_RPC_URL | Custom RPC endpoint | No |
AGENT_PRIVATE_KEY | Base58 private key | Yes* |
AGENT_WALLET_PATH | Path to keypair JSON | Yes* |
ATHR_MINT | ATHR token mint address | No |
USDC_MINT | USDC token mint address | No |
MERCHANT_WALLET_ADDRESS | Default recipient | No |
AGENT_PRIVATE_KEY or AGENT_WALLET_PATH is required.
Error Handling
Best Practices
- Always initialize - Call
init()before any operations - Check balance - Ensure sufficient token balance before creating payments
- Handle expiration - Payments expire after
maxTimeoutSeconds(default: 300s) - Secure keys - Never commit private keys to version control
- Use ATHR for lower fees - ATHR payments have lower marketplace fees than USDC
