Skip to main content

Building the Project

The CoW Protocol contracts project uses a hybrid build system compiling both Solidity smart contracts and TypeScript bindings.

Prerequisites

  • Node.js v16 or higher
  • Yarn package manager
  • Git

Installation

git clone https://github.com/cowprotocol/contracts.git
cd contracts
yarn install

Build Commands

Full Build

Compiles Solidity contracts and generates TypeScript bindings:
yarn build

Solidity Only

Runs Hardhat compiler with force flag:
yarn build:sol

TypeScript Only

Compiles in ESM, CommonJS, and default formats:
yarn build:ts

Compiler Settings

The project is configured for gas-efficient contract execution:
SettingValue
OptimizerEnabled
Optimizer Runs1,000,000
EVM VersionCancun
This prioritizes minimal execution costs over deployment expenses.

Output Structure

Successful builds generate:
DirectoryContents
out/Compiled Solidity contracts and artifacts
lib/esm/TypeScript ESM modules
lib/commonjs/TypeScript CommonJS modules

Linting and Formatting

Solidity

# Lint
yarn lint:sol

# Format
yarn fmt:sol

TypeScript

# Lint
yarn lint:ts

# Format
yarn fmt:ts

Troubleshooting

If you encounter build issues:
  1. Clear build artifacts:
    rm -rf out/ lib/ cache/
    
  2. Reinstall dependencies:
    rm -rf node_modules
    yarn install
    
  3. Force rebuild:
    yarn build:sol --force
    yarn build:ts
    
Last modified on March 4, 2026