REST API

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:

DirectionPaymentGas
Solana → Base$0.50 USDC via x402 protocolServer sponsors Solana gas; user reimburses ~$0.001 USDC
Base → SolanaFree (no x402)User pays Base gas directly (~$0.001 ETH)

Endpoints Reference

EndpointMethodAuthDescription
/api/chainsGETNoneList supported chains
/api/tokens/:chainGETNoneList tokens for a chain
/api/swap/quotePOSTNoneGet swap quote
/api/swap/executePOSTx402 (Solana-source only)Execute swap
/api/swap/:id/statusGETNonePoll swap status

Full OpenAPI spec: https://api.clawswap.dev/api/openapi

Solana → Base

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!

Base → Solana

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

FeeSolana → BaseBase → 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