v6 to v7 Migration Guide
Upgrade from CoW SDK v6 to v7 with the new adapter systemOverview
CoW SDK v7 is 99% backward compatible with v6. The primary change is the introduction of adapters that allow the SDK to work with different Web3 libraries (viem, ethers v6, and ethers v5).
In v7, you must set an adapter corresponding to the library you use:
ViemAdapter, EthersV6Adapter, or EthersV5Adapter.Key Changes
Required Adapters
v7 introduces a new adapter system that provides compatibility with multiple blockchain libraries:- ViemAdapter - For viem (recommended for new projects)
- EthersV6Adapter - For ethers.js v6
- EthersV5Adapter - For ethers.js v5
Installation
First, install the adapter package for your chosen Web3 library:- viem
- ethers v6
- ethers v5
Migration Steps
Basic Setup
The main difference is creating and passing an adapter when instantiating SDK classes.- v6
- v7
Adapter Setup Examples
- viem
- ethers v6
- ethers v5
Using setGlobalAdapter
Most SDK packages (e.g.,MetadataApi, OrderBookApi, BridgingSdk) accept an adapter parameter. However, you can also set a global adapter that will be used by all SDK instances:
When you provide an adapter directly to an SDK constructor, it takes precedence over the global adapter.
Wagmi Integration
When integrating with wagmi, you need to bind the SDK to your app’s account state. When the account or network changes in the wallet, update the SDK accordingly.Complete Wagmi Example
Migration Checklist
- Install the appropriate adapter package for your Web3 library
- Create an adapter instance with your provider and signer
- Pass the adapter when creating SDK instances, or use
setGlobalAdapter() - If using wagmi/React, create a hook to sync SDK with wallet state
- Update your TypeScript imports to include adapter packages
- Test that orders can be signed and posted with the new setup
Common Issues
Missing Adapter Error
If you see an error about a missing adapter, make sure you’ve either:- Passed an adapter directly to the SDK constructor, or
- Called
setGlobalAdapter()before using any SDK methods
Wagmi State Sync
When using wagmi, ensure your binding hook runs before attempting to use the SDK. Use theisSdkReady flag to control when SDK methods can be called.
Wrong Adapter Type
Make sure you’re using the correct adapter for your Web3 library:- viem ->
ViemAdapter - ethers v6 ->
EthersV6Adapter - ethers v5 ->
EthersV5Adapter
Next Steps
- Review the Trading SDK documentation for updated examples
- Check out the complete wagmi example in the repository
- Explore other adapter examples for viem and ethers