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

# Foundry

> Use Foundry to build, test, deploy, and debug contracts with the Monad execution environment.

[Foundry](https://getfoundry.sh/) v1.8 or later includes first-class Monad execution support across Forge, Anvil, Cast, Chisel, traces, and cheatcodes. Use the official Foundry distribution for Monad development.

For general Foundry usage, including writing tests and scripts, deployment, configuration, and cheatcodes, refer to the [Foundry documentation](https://getfoundry.sh/).

## Installation

Install the official Foundry installer:

```sh theme={null}
curl -L https://foundry.paradigm.xyz | bash
```

Follow the installer instructions to add `foundryup` to your shell, then install the latest stable Foundry release:

```sh theme={null}
foundryup
```

Confirm that you are running Foundry v1.8.0 or later:

```sh theme={null}
forge --version
```

<Warning>
  Foundry releases before v1.8 do not include Monad execution support.
</Warning>

## Configure Monad execution

Set the execution network in your project's `foundry.toml`:

```toml title="foundry.toml" theme={null}
[profile.default]
network = "monad"
```

This setting makes local Forge, Cast, and Chisel execution use Monad's gas model, opcode pricing, transaction rules, precompiles, and contract size limits.

You can select Monad for a single command instead:

```sh theme={null}
forge test --network monad
```

## Hardfork selection

Local Monad execution defaults to the latest supported Monad hardfork, currently `MonadTen`. To reproduce an earlier hardfork, set it explicitly:

```toml title="foundry.toml" theme={null}
[profile.default]
network = "monad"
hardfork = "monad:MonadNine"
```

You can also select a hardfork for a single command:

```sh theme={null}
forge test --network monad --hardfork MonadNine
```

When Foundry forks Monad Mainnet or Testnet, it uses the endpoint's chain ID and the forked block's timestamp to select the active Monad hardfork automatically.

## Monad execution features

| Feature                   | Description                                                                                                    |
| ------------------------- | -------------------------------------------------------------------------------------------------------------- |
| **Monad EVM execution**   | Monad gas model, opcode pricing, transaction rules, 128 KB contract size limit, and 256 KB initcode size limit |
| **Monad hardforks**       | Explicit hardfork selection and automatic selection for historical and live network forks                      |
| **MonadTen and MIP-8**    | Page-based storage access, write, and state-growth gas accounting                                              |
| **Monad precompiles**     | Monad precompile execution, staking cheatcodes, and human-readable trace decoding                              |
| **Anvil with Monad**      | Local or forked Monad execution using the official Anvil binary                                                |
| **Contract verification** | Monad-aware bytecode replay for Forge verification workflows                                                   |

For the complete list of protocol differences, see [Differences between Monad and Ethereum](/developer-essentials/differences).

## Anvil

Use `--network monad` to start a local Anvil node with the Monad execution environment:

```sh theme={null}
anvil --network monad
```

Anvil defaults to `MonadTen` for new local chains. You can also fork Monad Testnet or Mainnet:

```sh theme={null}
# Fork Monad Testnet
anvil --fork-url https://testnet-rpc.monad.xyz

# Fork Monad Mainnet
anvil --fork-url https://rpc.monad.xyz
```

When forking a canonical Monad endpoint, Anvil detects the Monad network from its chain ID and selects the active hardfork for the fork block.

## Cast and Chisel

Cast and Chisel use the Monad execution environment when `network = "monad"` is set in `foundry.toml`. You can also pass `--network monad` directly to supported commands.

All standard Cast and Chisel workflows remain available. Monad-specific precompile calls are decoded in traces with human-readable names and parameters.

## CI integration

Use the official [Foundry toolchain action](https://github.com/foundry-rs/foundry-toolchain) and install v1.8.0 or later:

```yaml theme={null}
- name: Install Foundry
  uses: foundry-rs/foundry-toolchain@v1
  with:
    version: v1.8.0
```

For example:

```yaml theme={null}
name: CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          submodules: recursive

      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1
        with:
          version: v1.8.0

      - name: Run tests with Monad execution
        run: forge test --network monad -vvv
```

## Migrating from Monad Foundry

<Warning>
  The legacy [Monad Foundry fork](https://github.com/category-labs/foundry/tree/monad) supports Monad execution only through the `MonadNine` hardfork. It does not support `MonadTen` or MIP-8 and should be migrated from.
</Warning>

To migrate:

1. Install Foundry v1.8 or later with the official installer and run `foundryup`.
2. Add `network = "monad"` to your `foundry.toml`, or pass `--network monad` to individual commands.
3. Replace `anvil --monad` with `anvil --network monad`.
4. Replace `category-labs/foundry-toolchain@v1` with `foundry-rs/foundry-toolchain@v1` in CI.
5. Remove scripts that install Foundry from `foundry.category.xyz` or run `foundryup --network monad`.

The official release includes the Monad execution behavior, precompiles, trace decoding, and tooling integration previously provided by the fork, along with MonadTen support.
