API Integration
Complete guide to integrating ClawSwap REST API with working examples
Easier options available: For AI agents, use the MCP server (no code required). For TypeScript apps, use the SDK (type-safe with built-in helpers). The REST API below gives you full control in any language.
Overview
Base URL: https://api.clawswap.dev
Interactive Docs: https://api.clawswap.dev/docs
ClawSwap API enables cross-chain token swaps between Solana and Base. Swaps are bidirectional:
| Direction | Payment | Gas |
|---|---|---|
| Solana → Base | $0.50 USDC via x402 protocol | Server sponsors Solana gas; user reimburses ~$0.001 USDC |
| Base → Solana | Free (no x402) | User pays Base gas directly (~$0.001 ETH) |
Endpoints Reference
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| /api/chains | GET | None | List supported chains |
| /api/tokens/:chain | GET | None | List tokens for a chain |
| /api/swap/quote | POST | None | Get swap quote |
| /api/swap/execute | POST | x402 (Solana-source only) | Execute swap |
| /api/swap/:id/status | GET | None | Poll swap status |
Full OpenAPI spec: https://api.clawswap.dev/api/openapi
Complete Example: Solana → Base
This example shows how to swap USDC from Solana to Base with x402 payment.
Install Dependencies
Complete Working Code
x402 Payment: The wrapFetchWithPayment wrapper automatically handles the $0.50 USDC payment on Solana. No manual payment setup required!
Complete Example: Base → Solana
This example shows how to swap USDC from Base to Solana (free, no x402 payment).
Install Dependencies
Complete Working Code
Critical: Always pass the gas field from the API response. This prevents intermittent failures caused by RPC state lag after approval transactions.
Status Polling
Use the status endpoint to track swap progress:
Status values:
- •
pending- Order created, waiting for source tx - •
created- Source transaction submitted - •
fulfilled- Swap completed successfully ✓ - •
completed- All confirmations done ✓ - •
cancelled- Order cancelled or refunded - •
failed- Swap failed
Recommended: Poll every 5 seconds. Average settlement: ~30 seconds.
Fee Summary
| Fee | Solana → Base | Base → Solana |
|---|---|---|
| x402 protocol fee | $0.50 USDC (on Solana) | Free |
| Gas reimbursement | ~$0.001 USDC (in swap tx) | User pays ~$0.001 ETH on Base |
| Bridge fee | ~$0.03-0.05 | ~$0.03-0.05 |
| Total | ~$0.53-0.55 | ~$0.03-0.05 + gas |