> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.getfoundry.sh/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

## Foundry on Monad

Official Foundry release and nightly builds include Monad support. Monad execution rules apply wherever you select the `monad` network family: in Forge tests and scripts, in Chisel, and in a local Anvil node. If you build Foundry from source, enable the `monad` Cargo feature; see [Network configuration](/config/networks#select-a-network).

This guide covers how Monad's differences show up in your Foundry workflow. Protocol details live in the [Monad developer docs](https://docs.monad.xyz) and the [Monad Improvement Proposals](https://github.com/monad-crypto/MIPs).

## Setup and configuration

### Create a Monad project

```bash
$ forge init --network monad my-monad-app
$ cd my-monad-app
```

This creates the standard Forge project and sets `network = "monad"` in `foundry.toml`.

### Configure `foundry.toml`

```toml [foundry.toml]
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
network = "monad"

[rpc_endpoints]
monad = "https://rpc.monad.xyz"
monad_testnet = "https://testnet-rpc.monad.xyz"
```

`network = "monad"` makes local tests, scripts and Chisel sessions use Monad rules when they aren't forking a live Monad RPC. The legacy `monad = true` form still works, but new projects should use `network`.

### Forks

Foundry recognizes Monad mainnet (chain ID `143`) and Monad testnet (chain ID `10143`), so forks of either run with Monad rules without `--network`:

```bash
$ forge test --fork-url monad_testnet
$ anvil --fork-url https://testnet-rpc.monad.xyz
```

See [Network configuration](/config/networks#fork-inference) for how fork inference works with other networks.

### Local Anvil

Run a local node with Monad rules:

```bash
$ anvil --network monad
```

### Hardforks

Foundry supports the `MonadEight`, `MonadNine` and `MonadTen` hardforks, and uses `MonadTen` by default. Monad hardforks must be namespaced with `monad:`; a bare `MonadNine` is read as an Ethereum hardfork and rejected.

```toml [foundry.toml]
[profile.historical]
network = "monad"
hardfork = "monad:MonadNine"
```

```bash
$ forge test --hardfork monad:MonadNine
```

Pin a hardfork only to reproduce historical behavior. Gas costs and available precompiles change between Monad hardforks.

## Gas

### Transactions are charged their gas limit

On Monad, a transaction pays for its full gas limit, not for the gas it uses, and this applies to reverted transactions too. Anvil in Monad mode reports the charged gas as `gasUsed` in receipts:

```bash
$ cast send 0x70997970C51812dc3A010C7d01b50e0d17dC79C8 --value 1 --gas-limit 100000 \
    --private-key $PRIVATE_KEY --rpc-url http://127.0.0.1:8545
$ cast receipt <TX_HASH> gasUsed --rpc-url http://127.0.0.1:8545
100000
```

The same ETH transfer on Ethereum would use 21,000 gas.

Set gas limits close to what a transaction needs. [`forge script`](/reference/forge/script) multiplies each gas estimate by `--gas-estimate-multiplier`, which defaults to `130`. On Monad that margin is paid in full, so consider a lower value when broadcasting:

```bash
$ forge script script/Deploy.s.sol --broadcast --rpc-url monad_testnet --gas-estimate-multiplier 110
```

Keep some margin when a transaction's cost depends on state that can change between simulation and inclusion.

### Gas reports differ from Ethereum

Monad's gas schedule differs from Ethereum's, so gas figures in test output, gas reports and snapshots change with the network. The `Counter` test that `forge init` generates reports different gas for `test_Increment` under each rule set:

| Network and hardfork | `test_Increment` gas |
|---|---|
| `monad` (`MonadTen`, default) | 77,213 |
| `monad:MonadNine` | 77,313 |
| `monad:MonadEight` | 77,347 |
| `ethereum` | 51,847 |

Compare gas snapshots only against snapshots taken with the same network and hardfork.

## Precompiles and cheatcodes

[`monad-std`](https://github.com/category-labs/monad-std) provides Solidity interfaces for Monad's precompiles and Monad-specific cheatcodes, and a `MonadTest` base contract:

```bash
$ forge install category-labs/monad-std
```

`MonadTest` does not include forge-std's assertions. Inherit forge-std's `Test` as well when you need them:

```solidity [test/Staking.t.sol]
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.13 <0.9.0;

import {Test} from "forge-std/Test.sol";
import {MonadTest} from "monad-std/MonadTest.sol";

contract StakingTest is Test, MonadTest {
    function test_EpochBoundary() public {
        monadVm.setEpoch(42, false);
        monadVm.epochBoundary(43);

        (uint64 epoch, bool inDelayPeriod) = staking.getEpoch();
        assertEq(epoch, 43);
        assertFalse(inDelayPeriod);
    }
}
```

Run these tests with Monad rules (`network = "monad"` or `--network monad`). The precompiles and the `MonadVm` cheatcodes don't exist under other networks.

### Staking precompile

`staking` is the staking precompile at `0x1000`, through the `IMonadStaking` interface. It reads the staking state that your test sets up with the `MonadVm` cheatcodes.

`getValidator` returns twelve values. A test that calls it can fail to compile with `Stack too deep` unless you enable the IR pipeline:

```toml [foundry.toml]
[profile.default]
via_ir = true
```

### Reserve balance precompile

`reserveBalance` is the reserve balance precompile at `0x1001` ([MIP-4](https://github.com/monad-crypto/MIPs/blob/main/MIPs/MIP-4.md)). It is available from `MonadNine` onward; under `monad:MonadEight` and under other networks, calls to it revert.

```solidity
assertFalse(reserveBalance.dippedIntoReserve());
```

### `MonadVm` cheatcodes

`monadVm` drives the staking precompile's system operations from a test:

| Cheatcode | What it does |
|---|---|
| `setEpoch(uint64 epoch, bool inDelayPeriod)` | Sets the current epoch and whether it is in the delay period |
| `setProposer(uint64 valId)` | Sets the current block proposer's validator ID |
| `setAccumulator(uint64 valId, uint256 value)` | Sets a validator's accumulated reward per token |
| `blockReward(address author, uint256 reward)` | Distributes a block reward through the real reward system call |
| `epochSnapshot()` | Runs the epoch snapshot system call |
| `epochChange(uint64 newEpoch)` | Runs the epoch change system call |
| `epochBoundary(uint64 newEpoch)` | Runs `epochSnapshot()` and then `epochChange(newEpoch)` |

Traces decode staking precompile calls and system calls by name.

## Related

* [Network configuration](/config/networks): select a network family and hardfork
* [Fork testing](/guides/fork-testing): run tests against a live Monad RPC
* [Foundry on Tempo](/guides/tempo): the equivalent guide for Tempo
