← Back to all products
$10
CoW Protocol SDK
SDK for integrating CoW Protocol batch auctions — off-chain matching, on-chain settlement.
TOMLPythonTypeScriptMarkdownJSON
📁 File Structure 20 files
cow-protocol-sdk/
├── LICENSE
├── README.md
├── examples/
│ ├── create-order.ts
│ ├── python-order.py
│ └── track-surplus.ts
├── package.json
├── python/
│ ├── cow_sdk/
│ │ ├── __init__.py
│ │ ├── client.py
│ │ ├── signer.py
│ │ └── types.py
│ └── pyproject.toml
├── security-notes.md
├── src/
│ ├── client/
│ │ ├── CowClient.ts
│ │ └── types.ts
│ ├── index.ts
│ ├── signing/
│ │ └── OrderSigner.ts
│ ├── surplus/
│ │ └── SurplusTracker.ts
│ └── utils/
│ ├── api.ts
│ └── constants.ts
└── tsconfig.json
📖 Documentation Preview README excerpt
CoW Protocol SDK
TypeScript/Python SDK for integrating CoW Protocol (Coincidence of Wants) surplus-based fee routing.
Product 3 of the [defi-router](../../) store. Part of the CryptoForge DeFi toolkit.
Price: $9.99 | License: MIT | TypeScript: ^5.5 | Python: ^3.10
What is CoW Protocol?
[CoW Protocol](https://cow.fi) (formerly Gnosis Protocol v2) is a trading protocol that finds the best prices for users by batching orders and executing them through a competitive solver auction — instead of routing directly through on-chain AMMs.
How it works
┌────────────────────────────────────────────────────────────────────┐
│ CoW Protocol Flow │
│ │
│ 1. User signs EIP-712 order 2. Order enters batch auction │
│ (off-chain, gasless) (every ~30 seconds) │
│ │
│ ┌─────────┐ sign ┌──────────────┐ batch ┌────────────────┐ │
│ │ User │ ──────→ │ Orderbook │ ───────→ │ Solver Auction │ │
│ │ (SDK) │ │ (api.cow.fi)│ │ (competitive) │ │
│ └─────────┘ └──────────────┘ └───────┬────────┘ │
│ │ │
│ 3. Solvers find optimal 4. Settlement on-chain│ │
│ execution paths via GPv2Settlement │ │
│ ▼ │
│ ┌─────────────────┐ ┌─────────────────────────────────┐ │
│ │ Coincidence of │ ◄──────│ GPv2Settlement Contract │ │
│ │ Wants (CoW) │ │ - Batch settlement │ │
│ │ = P2P matching │ │ - Surplus to users │ │
│ │ = Zero slippage │ │ - MEV protection │ │
│ └─────────────────┘ └─────────────────────────────────┘ │
└────────────────────────────────────────────────────────────────────┘
Why CoW Protocol?
| Feature | Traditional AMM | CoW Protocol |
|---|---|---|
| MEV Protection | None (sandwichable) | Batch auction prevents MEV |
| Price | Pool price + slippage | Solver competition finds best price |
| Surplus | Captured by MEV bots | Returned to users |
| Gas | User pays per swap | Solver pays, amortized over batch |
| P2P Matching | Not possible | Coincidence of Wants matching |
Installation
TypeScript
npm install @cryptoforge/cow-sdk ethers
# or
yarn add @cryptoforge/cow-sdk ethers
... continues with setup instructions, usage examples, and more.
📄 Code Sample .py preview
examples/python-order.py
"""
Example: Create a swap order on CoW Protocol using the Python SDK.
Demonstrates:
1. Getting a quote for a WETH → USDC swap
2. Signing and submitting the order
3. Polling for order status
Prerequisites:
pip install cryptoforge-cow-sdk
export PRIVATE_KEY=0x...
WARNING: Never hardcode private keys. This example reads from env vars.
"""
import asyncio
import os
import sys
from cow_sdk import (
CowClient,
CowClientConfig,
OrderKind,
QuoteRequest,
SupportedChainId,
)
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
PRIVATE_KEY = os.environ.get("PRIVATE_KEY")
if not PRIVATE_KEY:
print("Error: Set PRIVATE_KEY environment variable")
sys.exit(1)
CHAIN_ID = SupportedChainId.MAINNET
# Token addresses (Ethereum mainnet)
WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
# Sell 0.1 WETH (in wei)
SELL_AMOUNT = str(10**17) # 0.1 * 10^18
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
# ... 72 more lines ...