## `createFork`

### Signature

```solidity
function createFork(string calldata urlOrAlias) external returns (uint256 forkId);
function createFork(string calldata urlOrAlias, uint256 blockNumber) external returns (uint256 forkId);
function createFork(string calldata urlOrAlias, bytes32 txHash) external returns (uint256 forkId);
```

### Description

Creates a new fork from the given endpoint and returns the identifier of the fork. The fork is **not** automatically selected—use [`selectFork`](/reference/cheatcodes/select-fork) or [`createSelectFork`](/reference/cheatcodes/create-select-fork) to activate it.

### Parameters

| Parameter     | Type      | Description                                              |
|---------------|-----------|----------------------------------------------------------|
| `urlOrAlias`  | `string`  | RPC URL or alias from `foundry.toml` `[rpc_endpoints]`   |
| `blockNumber` | `uint256` | Block number to fork from (optional, defaults to latest) |
| `txHash`      | `bytes32` | Transaction hash to fork at (replays prior transactions) |

### Returns

| Parameter | Type      | Description                           |
|-----------|-----------|---------------------------------------|
| `forkId`  | `uint256` | Identifier for the created fork       |

### Examples

```solidity [test/CreateFork.t.sol]
function testCreateFork() public {
    // Fork at latest block
    uint256 forkId = vm.createFork(MAINNET_RPC_URL);
    vm.selectFork(forkId);
    
    // Fork at specific block
    uint256 historicalFork = vm.createFork(MAINNET_RPC_URL, 1_337_000);
    vm.selectFork(historicalFork);
    assertEq(block.number, 1_337_000);
}
```

### Related Cheatcodes

* [`selectFork`](/reference/cheatcodes/select-fork) - Activate a fork
* [`createSelectFork`](/reference/cheatcodes/create-select-fork) - Create and activate a fork in one call
* [`activeFork`](/reference/cheatcodes/active-fork) - Get the currently active fork
