> **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.

## Forking

Anvil can fork any EVM-compatible chain, allowing you to test against real-world state without deploying to a live network.

### Basic forking

```bash
$ anvil --fork-url https://ethereum.reth.rs/rpc
```

You can also fork from a specific point in the chain's history:

:::code-group
```bash [At block]
$ anvil --fork-url https://ethereum.reth.rs/rpc --fork-block-number 18000000
```

```bash [At transaction]
$ anvil --fork-url https://ethereum.reth.rs/rpc --fork-transaction-hash $TX_HASH
```
:::

### Skipping fork identity probes

By default, Anvil sends `anvil_nodeInfo` and, if it succeeds, `anvil_metadata` to detect whether the fork endpoint is another Anvil instance. Some public RPC gateways delay responses to these methods. You can skip both probes with `--no-fork-node-info`:

```bash
$ anvil --fork-url $RPC_URL --no-fork-node-info
```

The flag requires `--fork-url` and treats the endpoint as a regular chain. Standard RPC requests for chain ID, blocks, and gas price still run, subject to your other fork options. Leave the probes enabled when you need Anvil to inherit another Anvil instance's network and hardfork metadata.

See the [`anvil` reference](/reference/anvil/anvil) for all fork options.

### Chain configuration

When forking, Anvil inherits the chain ID from the remote endpoint by default.

```bash [Override chain ID]
$ anvil --fork-url https://ethereum.reth.rs/rpc --chain-id 1337
```

```bash [Specify hardfork]
$ anvil --fork-url https://ethereum.reth.rs/rpc --hardfork cancun
```

### Rate limiting

RPC providers often rate-limit requests. Anvil handles this automatically but you can tune the behavior:

```bash [Set compute units per second]
$ anvil --fork-url $RPC_URL --compute-units-per-second 100
```

```bash [Disable rate limiting]
$ anvil --fork-url $RPC_URL --no-rate-limit
```

```bash [Set retry count]
$ anvil --fork-url $RPC_URL --retries 10
```

### Caching

Anvil caches forked state to disk at `~/.foundry/cache/rpc/<chain>/<block>/` to speed up subsequent runs.

```bash [Disable storage caching]
$ anvil --fork-url $RPC_URL --no-storage-caching
```

### Custom headers

Some RPC providers require authentication headers:

```bash [Add custom header]
$ anvil --fork-url $RPC_URL --fork-header "Authorization: Bearer $TOKEN"
```

### L2 support

Anvil can fork L2 networks directly. The network family is inferred from the forked chain ID, so forking a network like Optimism needs no extra flags:

```bash [Fork Optimism]
$ anvil --fork-url https://mainnet.optimism.io
```

```bash [Enable Celo features]
$ anvil --fork-url https://forno.celo.org --celo
```

Use `--network` to select a network family explicitly. See
[Network configuration](/config/networks) for selection and inference behavior,
and the [`anvil` reference](/reference/anvil/anvil) for the values supported by
your installed binary.
