> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Epoch

> Consensus layer epoch (32 slots = 6.4 minutes)

## Overview

Epoch represents a consensus layer epoch in Ethereum's proof-of-stake system. Each epoch contains 32 slots (6.4 minutes) and serves as the fundamental period for validator duties, finality, and checkpoint organization.

**Type:** `bigint & { readonly [brand]: "Epoch" }`

## Key Concepts

* **Duration**: 32 slots = 6.4 minutes per epoch
* **Finality**: Two consecutive epochs must pass for finality
* **Validator committees**: Reshuffled every epoch
* **Rewards**: Calculated and distributed per epoch

## Methods

### `Epoch.from(value)`

Create Epoch from number, bigint, or string.

```typescript theme={null}
import { Epoch } from '@tevm/primitives';

const epoch1 = Epoch.from(100000n);
const epoch2 = Epoch.from(100000);
const epoch3 = Epoch.from("0x186a0");
```

### `Epoch.toNumber(epoch)`

Convert Epoch to number. Throws if exceeds MAX\_SAFE\_INTEGER.

```typescript theme={null}
const epoch = Epoch.from(100000n);
const num = Epoch.toNumber(epoch); // 100000
```

### `Epoch.toBigInt(epoch)`

Convert Epoch to bigint.

```typescript theme={null}
const epoch = Epoch.from(100000);
const big = Epoch.toBigInt(epoch); // 100000n
```

### `Epoch.equals(a, b)`

Check if two epochs are equal.

```typescript theme={null}
const a = Epoch.from(100000n);
const b = Epoch.from(100000n);
Epoch.equals(a, b); // true
```

### `Epoch.toSlot(epoch)`

Convert epoch to the first slot of that epoch (epoch \* 32).

```typescript theme={null}
const epoch = Epoch.from(3n);
const slot = Epoch.toSlot(epoch); // Slot 96
```

## Usage Examples

### Calculate epoch timing

```typescript theme={null}
import { Epoch } from '@tevm/primitives';

const genesisTime = 1606824023; // Beacon chain genesis
const epoch = Epoch.from(100000n);

// Calculate timestamp for epoch start
const epochTime = genesisTime + Number(epoch) * 32 * 12;
console.log(`Epoch ${epoch} started at: ${new Date(epochTime * 1000)}`);
```

### Work with finality

```typescript theme={null}
import { Epoch } from '@tevm/primitives';

const justifiedEpoch = Epoch.from(100n);
const finalizedEpoch = Epoch.from(98n);

// Check if justified epoch can finalize
const canFinalize = justifiedEpoch - finalizedEpoch >= 2n;
console.log(`Can finalize: ${canFinalize}`);
```

### Convert between slots and epochs

```typescript theme={null}
import { Epoch, Slot } from '@tevm/primitives';

const epoch = Epoch.from(5n);
const firstSlot = Epoch.toSlot(epoch); // 160
const lastSlot = Epoch.toSlot(Epoch.from(epoch + 1n)) - 1n; // 191

console.log(`Epoch ${epoch} spans slots ${firstSlot} to ${lastSlot}`);
```

## Related Types

* [Slot](/primitives/slot) - Individual 12-second time unit
* [ValidatorIndex](/primitives/validator-index) - Validator registry index
* [Withdrawal](/primitives/withdrawal) - Validator withdrawal structure

## References

* [Ethereum Consensus Specs](https://github.com/ethereum/consensus-specs)
* [Gasper](https://ethereum.org/en/developers/docs/consensus-mechanisms/pos/gasper/) - Finality mechanism
