## `createSelectFork`

### Signature

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

### Description

Creates **and** selects a new fork from the given endpoint and returns the identifier of the fork. This is equivalent to calling [`createFork`](/reference/cheatcodes/create-fork) followed by [`selectFork`](/reference/cheatcodes/select-fork).

### 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/CreateSelectFork.t.sol]
function testCreateSelectFork() public {
    // Create and select in one call
    uint256 forkId = vm.createSelectFork(MAINNET_RPC_URL);
    assertEq(vm.activeFork(), forkId);

    // Fork at specific block
    uint256 historicalFork = vm.createSelectFork(MAINNET_RPC_URL, 1_337_000);
    assertEq(block.number, 1_337_000);
}
```

### Related Cheatcodes

* [`createFork`](/reference/cheatcodes/create-fork) - Create a fork without selecting
* [`selectFork`](/reference/cheatcodes/select-fork) - Select an existing fork
* [`activeFork`](/reference/cheatcodes/active-fork) - Get the currently active fork
