Skip to main content

Overview

ValidatorIndex represents a validator’s unique index in the beacon chain state registry. Each validator receives an immutable index when they activate, which persists for their entire lifecycle. Type: number & { readonly [brand]: "ValidatorIndex" }

Key Concepts

  • Immutable: Index assigned at activation, never changes
  • Sequential: Indices assigned sequentially starting from 0
  • Permanent: Index retained even after validator exits
  • Registry: Maps to validator entry in beacon state

Methods

ValidatorIndex.from(value)

Create ValidatorIndex from number, bigint, or string.
import { ValidatorIndex } from '@tevm/primitives';

const idx1 = ValidatorIndex.from(123456);
const idx2 = ValidatorIndex.from(123456n);
const idx3 = ValidatorIndex.from("0x1e240");

ValidatorIndex.toNumber(index)

Convert ValidatorIndex to number.
const idx = ValidatorIndex.from(123456);
const num = ValidatorIndex.toNumber(idx); // 123456

ValidatorIndex.equals(a, b)

Check if two validator indices are equal.
const a = ValidatorIndex.from(123456);
const b = ValidatorIndex.from(123456);
ValidatorIndex.equals(a, b); // true

Usage Examples

Work with validator data

import { ValidatorIndex } from '@tevm/primitives';

interface ValidatorInfo {
  index: ValidatorIndex;
  pubkey: Uint8Array;
  withdrawalAddress: string;
  balance: bigint;
}

const validator: ValidatorInfo = {
  index: ValidatorIndex.from(123456),
  pubkey: new Uint8Array(48),
  withdrawalAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f251e3",
  balance: 32000000000n, // 32 ETH in Gwei
};

Track validator committees

import { ValidatorIndex, Epoch } from '@tevm/primitives';

interface Committee {
  epoch: Epoch;
  slot: number;
  validators: ValidatorIndex[];
}

const committee: Committee = {
  epoch: Epoch.from(100n),
  slot: 3200,
  validators: [
    ValidatorIndex.from(100),
    ValidatorIndex.from(200),
    ValidatorIndex.from(300),
  ],
};
  • Withdrawal - References validator by index
  • Slot - Validators assigned to specific slots
  • Epoch - Committee assignments per epoch

References