SDK
Type-safe TypeScript SDK for programmatic cross-chain swaps
Using an AI agent? The MCP server is easier β no code required. The SDK is for custom apps, bots, and programmatic access.
Why Use the SDK?
- βType Safety β Full TypeScript support with autocomplete and type checking
- βStatus Polling β Built-in
waitForSettlement()polls until swap completes - βTyped Errors β Specific error classes for each failure type
- βFramework Agnostic β Works with any fetch implementation, browser or server
Installation
Solana β Base
Solana-source swaps require x402 payment ($0.50 USDC). Gas is sponsored by ClawSwap.
Base β Solana
Base-source swaps are free β no x402 payment needed. Agent pays ~$0.001 gas on Base.
API Reference
new ClawSwapClient(config?)
Create a client. Pass { fetch: wrappedFetch } for x402-enabled Solana-source swaps.
client.getQuote(request)
Get a price quote. Free, no payment required.
client.executeSwap(request)
Execute a swap. Returns transaction data to sign and submit.
client.getStatus(requestId)
Check swap status. Returns current state: pending, submitted, filling, completed, or failed.
client.waitForSettlement(requestId, options?)
Poll until swap reaches terminal state. Configurable timeout (default 5min) and interval (default 3s).
client.getSupportedChains() / client.getSupportedTokens(chainId)
Discovery helpers. Cached for 1 hour.
Error Handling
Other error classes: MissingFieldError, UnsupportedChainError, UnsupportedRouteError, AmountTooLowError, NetworkError, TimeoutError, and more.
Resources
Features
Bidirectional Swaps
SolanaβBase and BaseβSolana with the same API
x402 Compatible
Pass an x402-wrapped fetch for automatic payment handling
Browser Ready
Zero Node.js dependencies β works in any environment with Fetch API
Token Discovery
Methods to list supported chains and tokens dynamically