## `rollFork`

### Signature

```solidity
function rollFork(uint256 blockNumber) external;
function rollFork(bytes32 txHash) external;
function rollFork(uint256 forkId, uint256 blockNumber) external;
function rollFork(uint256 forkId, bytes32 txHash) external;
```

### Description

Sets `block.number` for a fork. If no fork identifier is passed, it updates the currently active fork. Otherwise, it updates the specified fork.

If a transaction hash is provided, it rolls the fork to the block containing that transaction and replays all previously executed transactions.

### Parameters

| Parameter     | Type      | Description                                              |
|---------------|-----------|----------------------------------------------------------|
| `blockNumber` | `uint256` | The block number to roll to                              |
| `txHash`      | `bytes32` | Transaction hash to roll to (replays prior transactions) |
| `forkId`      | `uint256` | Fork to update (optional, defaults to active fork)       |

### Examples

#### Roll the active fork

```solidity [test/RollFork.t.sol]
function testRollFork() public {
    uint256 forkId = vm.createSelectFork(MAINNET_RPC_URL, 15_000_000);
    assertEq(block.number, 15_000_000);

    vm.rollFork(15_000_100);
    assertEq(block.number, 15_000_100);
}
```

#### Roll a specific fork

```solidity [test/RollForkById.t.sol]
function testRollForkById() public {
    uint256 optimismFork = vm.createFork(OPTIMISM_RPC_URL);
    
    // Roll the fork without selecting it
    vm.rollFork(optimismFork, 1_337_000);
    
    vm.selectFork(optimismFork);
    assertEq(block.number, 1_337_000);
}
```

### Related Cheatcodes

* [`roll`](/reference/cheatcodes/roll) - Set block number (non-fork)
* [`createFork`](/reference/cheatcodes/create-fork) - Create a new fork
* [`selectFork`](/reference/cheatcodes/select-fork) - Select a fork
