Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/ForkId

primitives/ForkId

Type Aliases

ForkIdType

ForkIdType = object
Defined in: src/primitives/ForkId/ForkIdType.ts:9 EIP-2124 Fork Identifier Used in DevP2P for fork detection and network validation

See

https://eips.ethereum.org/EIPS/eip-2124

Properties

hash
readonly hash: Uint8Array
Defined in: src/primitives/ForkId/ForkIdType.ts:13 CRC32 checksum of all fork hashes up to this point (4 bytes)
next
readonly next: BlockNumberType
Defined in: src/primitives/ForkId/ForkIdType.ts:18 Block number of next upcoming fork (0 if no known forks)

Variables

ForkId

const ForkId: object
Defined in: src/primitives/ForkId/index.ts:28

Type Declaration

from()
from: (value) => ForkIdType
Create ForkId from hash and next block number
Parameters
value
Fork ID components
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint
Returns
ForkIdType ForkId
Example
const forkId = ForkId.from({
  hash: new Uint8Array([0xfc, 0x64, 0xec, 0x04]),
  next: 1920000n,
});
matches()
matches: (local, remote) => boolean
Parameters
local
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint
remote
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint
Returns
boolean
toBytes()
toBytes: (forkId) => Uint8Array
Parameters
forkId
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint
Returns
Uint8Array

Functions

_matches()

_matches(local, remote): boolean
Defined in: src/primitives/ForkId/matches.js:23 Check if two ForkIds are compatible (EIP-2124 fork validation) Compatible if:
  1. Hashes match and next blocks match (identical)
  2. Hashes match and remote next is 0 (remote knows of no future forks)
  3. Hashes match and local next is 0 (local knows of no future forks)
  4. Hashes differ but remote next is >= local next (remote is ahead but compatible)

Parameters

local
ForkIdType Local ForkId
remote
ForkIdType Remote peer’s ForkId

Returns

boolean True if compatible

Example

const compatible = ForkId.matches(localForkId, peerForkId);
if (!compatible) {
  console.log("Fork incompatible - disconnect peer");
}

_toBytes()

_toBytes(forkId): Uint8Array<ArrayBufferLike>
Defined in: src/primitives/ForkId/toBytes.js:15 Encode ForkId to bytes (for DevP2P handshake) Format: [hash (4 bytes) || next (8 bytes big-endian)]

Parameters

forkId
ForkIdType ForkId to encode

Returns

Uint8Array<ArrayBufferLike> 12-byte encoding

Example

const bytes = ForkId.toBytes(forkId);
console.log(bytes.length); // 12

from()

from(value): ForkIdType
Defined in: src/primitives/ForkId/from.js:18 Create ForkId from hash and next block number

Parameters

value
Fork ID components
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint

Returns

ForkIdType ForkId

Example

const forkId = ForkId.from({
  hash: new Uint8Array([0xfc, 0x64, 0xec, 0x04]),
  next: 1920000n,
});

matches()

matches(local, remote): boolean
Defined in: src/primitives/ForkId/index.ts:17

Parameters

local
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint
remote
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint

Returns

boolean

toBytes()

toBytes(forkId): Uint8Array
Defined in: src/primitives/ForkId/index.ts:13

Parameters

forkId
hash
string | number | Uint8Array<ArrayBufferLike>
next
string | number | bigint

Returns

Uint8Array