Package installation
Install the @cowprotocol/contracts package using your preferred package manager:
npm install @cowprotocol/contracts
Peer dependencies
The package requires ethers version 5.4.0 or higher as a peer dependency. Install it if you haven’t already:
npm install ethers@^5.4.0
The package is designed for ethers v5. Compatibility with ethers v6 is not guaranteed.
Basic setup
Once installed, you can import the SDK utilities in your TypeScript or JavaScript project:
import {
domain,
Order,
OrderKind,
OrderBalance,
signOrder,
SigningScheme,
} from "@cowprotocol/contracts";
TypeScript support
The package includes full TypeScript type definitions. When using TypeScript, you’ll get auto-completion and type checking for all SDK functions:
import { Order, OrderKind } from "@cowprotocol/contracts";
const order: Order = {
sellToken: "0x...",
buyToken: "0x...",
sellAmount: "1000000000000000000",
buyAmount: "2000000000000000000",
validTo: Math.floor(Date.now() / 1000) + 3600,
appData: "0x0000000000000000000000000000000000000000000000000000000000000000",
feeAmount: "0",
kind: OrderKind.SELL,
partiallyFillable: false,
};
Contract artifacts
The package also includes compiled contract artifacts and deployment information:
import { deployments } from "@cowprotocol/contracts";
// Access deployed contract addresses
const networks = require("@cowprotocol/contracts/networks.json");
Building from source
If you want to build the package from source:
Clone the repository
git clone https://github.com/cowprotocol/contracts.git
cd contracts
Build the project
This compiles both Solidity contracts and TypeScript SDK.
The build process generates both CommonJS and ESM modules for maximum compatibility.
Next steps
Now that you have the package installed, learn how to create and sign your first order:
Quickstart Guide
Create and sign a CoW Protocol order