# activeFork

Description: activeFork cheatcode documentation

Note: This document was authored using MDX

  Source: https://github.com/NomicFoundation/hardhat-website/tree/main/src/content/docs/docs/reference/cheatcodes/Forking/active-fork.mdx

{/* This document contains content copied/adapted from the Foundry Book (MIT licensed). See LICENSE in the parent directory. */}

### Signature

```solidity
function activeFork() external returns (uint256);
```

### Description

Returns the identifier for the currently active fork. Reverts if no fork is currently active.

### Examples

Get the currently active fork id:

```solidity
uint256 mainnetForkId = vm.createFork(MAINNET_RPC_URL);
uint256 optimismForkId = vm.createFork(OPTIMISM_RPC_URL);

assert(mainnetForkId != optimismForkId);

vm.selectFork(mainnetForkId);
assertEq(vm.activeFork(), mainnetForkId);

vm.selectFork(optimismForkId);
assertEq(vm.activeFork(), optimismForkId);
```

### SEE ALSO

- [createFork](/docs/reference/cheatcodes/forking/create-fork)
- [selectFork](/docs/reference/cheatcodes/forking/select-fork)
