CoW Protocol SDK Quickstart Guide
This documentation provides a comprehensive walkthrough for executing your first token swap using the CoW Protocol SDK in under five minutes.Key Prerequisites
Before starting, ensure you have:- Node.js version 16 or higher
- A wallet containing a private key for transaction signing
- An RPC endpoint URL (Alchemy, Infura, or Tenderly)
- Test tokens on Sepolia testnet
Installation & Setup
The SDK requires three core packages:.env file with your PRIVATE_KEY and RPC_URL. Never commit this file to version control.
Web3 Adapter Configuration
The guide provides implementations for three frameworks:- Viem: Using
createPublicClientandprivateKeyToAccount - Ethers v6: Using
JsonRpcProviderandWallet - Ethers v5: Using
ethers.providers.JsonRpcProvider
Core Swap Process
The workflow follows these steps:- Initialize TradingSdk with chain ID, app identifier, and adapter
- Request a quote specifying sell/buy tokens, amounts, and slippage tolerance
- Review quote results including minimum amounts and validity period
- Sign and post the order using the quote function
- Retrieve order ID for tracking and explorer verification
Order Configuration Options
- Order Types:
SELL(exact amount out) orBUY(exact amount in) - Slippage: Expressed in basis points (50 = 0.5%, 100 = 1%)
- Custom Receiver: Send tokens to a different address
- Validity Period: Control order expiration timing
- Partial Fills: Enable or disable fractional execution
Token Approval Requirements
Before swapping, you must approve CoW Protocol to access your tokens. The SDK provides helper methods to check current allowance and execute approvals if needed.Monitoring & Order Statuses
After posting, orders can be tracked with statuses including:open- awaiting executionfulfilled- completely filledexpired- validity period elapsedcancelled- user-initiated cancellation
Troubleshooting Common Issues
The documentation addresses frequent problems:- Insufficient balance: Obtain test tokens from the Sepolia faucet
- Allowance errors: Complete token approval before swapping
- Expired quotes: Refresh quotes within the validity window
- RPC failures: Verify endpoint URLs or try alternative providers
- Invalid private keys: Confirm 64-character hex format with “0x” prefix
Developer Attribution (UTM Tracking)
The SDK automatically includes UTM tracking in all orders to attribute trading volume to developers. Default parameters:advancedSettings.appData.metadata.utm:
Providing any
utm field gives you full control — the SDK will not add defaults. Use utmContent for graffiti without affecting your appCode.