Skip to main content

Package Installation

Install the main SDK package using your preferred package manager:

Choose Your Adapter

The CoW SDK requires an adapter to interact with the blockchain. Choose the adapter that matches your Web3 library:

Viem

Modern, lightweight TypeScript library

Ethers v6

Latest version of ethers.js

Ethers v5

Legacy ethers.js version

Install Viem Adapter

Setup Example

Using wagmi? You can use useWalletClient() hook instead of privateKeyToAccount for the signer parameter.

Peer Dependencies

The CoW Protocol SDK has the following peer dependencies that may need to be installed depending on your use case:

Required

Optional

These dependencies are only required for specific advanced features:
  • ipfs-only-hash and multiformats - Required for app-data metadata features
  • @openzeppelin/merkle-tree - Required for merkle tree operations in programmatic orders

Verification

Verify your installation by importing the SDK:

Version Information

Current SDK version: v7.4.1
If you’re migrating from v6, see the Migration Guide for important breaking changes and upgrade instructions.

TypeScript Configuration

The CoW Protocol SDK is written in TypeScript and includes type definitions. Ensure your tsconfig.json has:

Environment Setup

Node.js Requirements

The SDK requires Node.js version 16 or higher:

Environment Variables

For development, create a .env file to store sensitive information:
.env
Security: Never commit private keys or RPC URLs to version control. Always use environment variables or secure key management solutions.

Framework-Specific Setup

React / Next.js

For React applications, you’ll typically use the SDK with wagmi or Rainbow Kit:
See the React Integration Example for complete setup.

Node.js

For Node.js scripts and backend services:
See the Node.js Usage Example for complete setup.

Next Steps

Quickstart Guide

Create your first swap in under 5 minutes

Adapters Concepts

Learn more about adapter configuration

Trading SDK API

Explore the complete TradingSdk API

Examples

Browse working code examples

Troubleshooting

Ensure all peer dependencies are installed. Run:
or install optional dependencies if using advanced features.
Make sure you’re using the correct adapter for your Web3 library version. Check that:
  • Viem adapter requires viem version 1.x or higher
  • Ethers v6 adapter requires ethers version 6.x
  • Ethers v5 adapter requires ethers version 5.7.x
Verify your RPC URL is correct and accessible:
Consider using services like Alchemy, Infura, or Tenderly for production.
Ensure the chain ID in your adapter setup matches the chain ID in the TradingSdk:

Getting Help

If you encounter issues during installation: