> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cow.bleu.builders/llms.txt
> Use this file to discover all available pages before exploring further.

# Building

> Compiling CoW Protocol contracts, including Solidity smart contracts and TypeScript bindings

# 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

```bash theme={null}
git clone https://github.com/cowprotocol/contracts.git
cd contracts
yarn install
```

## Build Commands

### Full Build

Compiles Solidity contracts and generates TypeScript bindings:

```bash theme={null}
yarn build
```

### Solidity Only

Runs Hardhat compiler with force flag:

```bash theme={null}
yarn build:sol
```

### TypeScript Only

Compiles in ESM, CommonJS, and default formats:

```bash theme={null}
yarn build:ts
```

## Compiler Settings

The project is configured for gas-efficient contract execution:

| Setting        | Value     |
| -------------- | --------- |
| Optimizer      | Enabled   |
| Optimizer Runs | 1,000,000 |
| EVM Version    | Cancun    |

This prioritizes minimal execution costs over deployment expenses.

## Output Structure

Successful builds generate:

| Directory       | Contents                                  |
| --------------- | ----------------------------------------- |
| `out/`          | Compiled Solidity contracts and artifacts |
| `lib/esm/`      | TypeScript ESM modules                    |
| `lib/commonjs/` | TypeScript CommonJS modules               |

## Linting and Formatting

### Solidity

```bash theme={null}
# Lint
yarn lint:sol

# Format
yarn fmt:sol
```

### TypeScript

```bash theme={null}
# Lint
yarn lint:ts

# Format
yarn fmt:ts
```

## Troubleshooting

If you encounter build issues:

1. **Clear build artifacts:**
   ```bash theme={null}
   rm -rf out/ lib/ cache/
   ```

2. **Reinstall dependencies:**
   ```bash theme={null}
   rm -rf node_modules
   yarn install
   ```

3. **Force rebuild:**
   ```bash theme={null}
   yarn build:sol --force
   yarn build:ts
   ```
