Skip to main content

CoW Protocol Contracts

Production-ready smart contracts and TypeScript SDK for building on Gnosis Protocol v2. Create batch auction orders, integrate with solvers, and settle trades on-chain across multiple networks.

Quick start

Get up and running with CoW Protocol in minutes

1

Install the package

Install the CoW Protocol contracts package via npm or yarn:
npm install @cowprotocol/contracts
2

Create an order

Import the SDK and create a signed order:
import { Order, domain, signOrder, computeOrderUid } from "@cowprotocol/contracts";
import { ethers } from "ethers";

const order: Order = {
  sellToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
  buyToken: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
  receiver: ethers.constants.AddressZero,
  sellAmount: ethers.utils.parseEther("1.0"),
  buyAmount: ethers.utils.parseEther("1000"),
  validTo: Math.floor(Date.now() / 1000) + 3600,
  appData: ethers.constants.HashZero,
  feeAmount: ethers.utils.parseEther("0.01"),
  kind: "sell",
  partiallyFillable: false,
};

const settlementContract = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41";
const chainId = 1;

const signature = await signOrder(
  domain(chainId, settlementContract),
  order,
  signer,
  "eip712"
);
3

Submit to the protocol

Submit your signed order to the CoW Protocol API for settlement:
const orderUid = computeOrderUid(domain(chainId, settlementContract), order, signer.address);

// Submit to CoW Protocol API
const response = await fetch("https://api.cow.fi/mainnet/api/v1/orders", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    ...order,
    signature,
    signingScheme: "eip712",
    from: await signer.getAddress(),
  }),
});
Your order will be included in the next batch auction and settled by solvers when a favorable match is found.

Explore by topic

Deep dive into CoW Protocol’s architecture and capabilities

Core concepts

Understand batch auctions, settlements, orders, and the solver network

Smart contracts

Explore the settlement contract, vault relayer, and authentication system

TypeScript SDK

Learn to create orders, sign messages, and encode settlements

Multi-chain deployments

Access contract addresses across Ethereum, Gnosis, Arbitrum, and more

Key features

Everything you need to build on CoW Protocol

Batch auction settlement

Execute multiple orders in a single transaction with optimal price discovery through competitive solver auctions

EIP-712 order signing

Secure order creation with typed data signing, supporting multiple signature schemes including EIP-1271

Multi-chain support

Deployed on 8+ networks including Ethereum, Gnosis Chain, Arbitrum, Optimism, Base, Polygon, BSC, and Avalanche

Flexible order types

Support for fill-or-kill, partial fills, buy/sell orders, and custom balance management via Balancer Vault

Ready to build?

Start integrating CoW Protocol into your application today. Follow our quickstart guide to create your first order in minutes.

Get started now