Overview
Adapters provide a unified interface for the CoW Protocol SDK to work with different Ethereum libraries. They abstract away library-specific implementations, allowing you to use your preferred web3 library while maintaining consistent SDK functionality.Available Adapters
The SDK provides three official adapters:Viem
Modern, lightweight TypeScript library
Ethers v6
Latest version of the popular Ethers library
Ethers v5
Legacy Ethers version for existing projects
ViemAdapter
TheViemAdapter connects the SDK to Viem, a modern TypeScript Ethereum library with excellent type safety and tree-shaking support.
Installation
Setup
Using with WalletClient
If you already have aWalletClient (e.g., from Wagmi or RainbowKit):
EthersV6Adapter
TheEthersV6Adapter integrates with Ethers.js v6, the latest major version with improved TypeScript support and modern JavaScript features.
Installation
Setup
Using RPC URL Directly
You can pass an RPC URL string instead of a provider instance:Browser Wallet Integration
EthersV5Adapter
TheEthersV5Adapter supports Ethers.js v5 for projects that haven’t migrated to v6.
Installation
Setup
Browser Integration (v5)
Adapter Interface
All adapters implement a common interface from@cowprotocol/sdk-common:
Dynamic Signer Management
All adapters support changing the signer after initialization:Choosing an Adapter
Use ViemAdapter when...
Use ViemAdapter when...
- Starting a new project with modern TypeScript
- Bundle size is a concern (Viem is smaller)
- You want the best TypeScript experience
- Using Next.js, Wagmi, or RainbowKit
Use EthersV6Adapter when...
Use EthersV6Adapter when...
- You’re already using Ethers v6 in your project
- You need the latest Ethers features
- Migrating from v5 to v6
Use EthersV5Adapter when...
Use EthersV5Adapter when...
- You have an existing project on Ethers v5
- Dependencies require Ethers v5
- You’re not ready to migrate to v6
Best Practices
Set Global Adapter Early
Call
setGlobalAdapter() before initializing any SDK classes to ensure all components use the correct adapter.Reuse Adapter Instances
Create one adapter instance and reuse it across your application to avoid unnecessary overhead.
Handle Provider Changes
When users switch networks or accounts, update the adapter using
setProvider() or setSigner() methods.Type Safety
Leverage TypeScript’s type inference with adapters for compile-time safety when working with contract ABIs.
Next Steps
Order Types
Learn about different order types in CoW Protocol
Trading SDK
Start building with the Trading SDK