ethereumjs-monorepo

@ethereumjs/common


@ethereumjs/common / Common

Class: Common

Defined in: common.ts:46

Common class to access chain and hardfork parameters and to provide a unified and shared view on the network and hardfork state.

Use createCustomCommon for simple custom-chain setups and createCommonFromGethGenesis to build a Common instance from a Geth genesis file. For full control over chain parameters, pass a ChainConfig to the constructor below.

Constructors

Constructor

new Common(opts): Common

Defined in: common.ts:67

Create a Common instance for a chain configuration and optional hardfork/EIP overrides.

Parameters

opts

CommonOpts

Returns

Common

Properties

customCrypto

readonly customCrypto: CustomCrypto

Defined in: common.ts:56

Optional crypto overrides from BaseOpts.customCrypto.


DEFAULT_HARDFORK

readonly DEFAULT_HARDFORK: string

Defined in: common.ts:48

Default hardfork from chain config (falls back to Hardfork.Prague).


events

events: EventEmitter<CommonEvent>

Defined in: common.ts:64

Emits hardforkChanged when the active hardfork updates.

Methods

activeOnBlock()

activeOnBlock(blockNumber): boolean

Defined in: common.ts:510

Alias to hardforkIsActiveOnBlock when hardfork is set

Parameters

blockNumber

BigIntLike

Returns

boolean

True if HF is active on block number


bootstrapNodes()

bootstrapNodes(): BootstrapNodeConfig[]

Defined in: common.ts:788

Returns bootstrap nodes for the current chain.

Returns

BootstrapNodeConfig[]

Array of bootstrap node configs


chainId()

chainId(): bigint

Defined in: common.ts:811

Returns the Id of current chain

Returns

bigint

chain Id


chainName()

chainName(): string

Defined in: common.ts:819

Returns the name of current chain

Returns

string

chain name (lower case)


consensusAlgorithm()

consensusAlgorithm(): string

Defined in: common.ts:860

Returns the concrete consensus implementation algorithm or protocol for the network e.g. “ethash” for “pow” consensus type, “clique” for “poa” consensus type or “casper” for “pos” consensus type.

Note: This value can update along a Hardfork.

Returns

string


consensusConfig()

consensusConfig(): object

Defined in: common.ts:886

Returns a dictionary with consensus configuration parameters based on the consensus algorithm

Expected returns (parameters must be present in the respective chain JSON files):

ethash: empty object clique: period, epoch casper: empty object

Note: This value can update along a Hardfork.

Returns

object


consensusType()

consensusType(): string

Defined in: common.ts:838

Returns the consensus type of the network Possible values: “pow”|”poa”|”pos”

Note: This value can update along a Hardfork.

Returns

string


copy()

copy(): Common

Defined in: common.ts:907

Returns a deep copy of this Common instance.

Returns

Common


dnsNetworks()

dnsNetworks(): string[]

Defined in: common.ts:795

Returns DNS ENR URLs for the current chain.

Returns

string[]


eipBlock()

eipBlock(eip): bigint | null

Defined in: common.ts:577

Returns the hardfork change block for eip

Parameters

eip

number

EIP number

Returns

bigint | null

Block number or null if unscheduled


eips()

eips(): number[]

Defined in: common.ts:828

Returns the additionally activated EIPs (by using the eips constructor option)

Returns

number[]

List of EIPs


eipTimestamp()

eipTimestamp(eip): bigint | null

Defined in: common.ts:595

Returns the scheduled timestamp of the EIP (if scheduled and scheduled by timestamp)

Parameters

eip

number

EIP number

Returns

bigint | null

Scheduled timestamp. If this EIP is unscheduled, or the EIP is scheduled by block number, then it returns null.


forkHash()

forkHash(hardfork?, genesisHash?): `0x${string}`

Defined in: common.ts:711

Returns an eth/64 compliant fork hash (EIP-2124)

Parameters

hardfork?

string

Hardfork name, optional if HF set

genesisHash?

Uint8Array<ArrayBufferLike>

Genesis block hash of the network, optional if already defined and not needed to be calculated

Returns

`0x${string}`

Fork hash as a hex string


genesis()

genesis(): GenesisBlockConfig

Defined in: common.ts:760

Returns the Genesis parameters of the current chain

Returns

GenesisBlockConfig

Genesis dictionary


getBlobGasSchedule()

getBlobGasSchedule(): BpoSchedule

Defined in: common.ts:458

Returns the blob gas schedule for the current hardfork

Returns

BpoSchedule

The blob gas schedule


getHardforkBy()

getHardforkBy(opts): string

Defined in: common.ts:172

Returns the hardfork either based on block number (older HFs) or timestamp (Shanghai upwards).

Parameters

opts

HardforkByOpts

Block number or timestamp

Returns

string

The name of the HF


gteHardfork()

gteHardfork(hardfork): boolean

Defined in: common.ts:540

Alias to hardforkGteHardfork when hardfork is set

Parameters

hardfork

string

Hardfork name

Returns

boolean

True if hardfork set is greater than hardfork provided


hardfork()

hardfork(): string

Defined in: common.ts:803

Returns the hardfork set

Returns

string

Hardfork name


hardforkBlock()

hardforkBlock(hardfork?): bigint | null

Defined in: common.ts:549

Returns the hardfork change block for hardfork provided or set

Parameters

hardfork?

string

Hardfork name, optional if HF set

Returns

bigint | null

Block number or null if unscheduled


hardforkForForkHash()

hardforkForForkHash(forkHash): HardforkTransitionConfig | null

Defined in: common.ts:732

Look up the hardfork transition entry for a fork hash.

Parameters

forkHash

string

EIP-2124 fork hash as a hex string

Returns

HardforkTransitionConfig | null

The matching transition config, or null when unknown


hardforkGteHardfork()

hardforkGteHardfork(hardfork1, hardfork2): boolean

Defined in: common.ts:520

Sequence based check if given or set HF1 is greater than or equal HF2

Parameters

hardfork1

string | null

Hardfork name or null (if set)

hardfork2

string

Hardfork name

Returns

boolean

True if HF1 gte HF2


hardforkIsActiveOnBlock()

hardforkIsActiveOnBlock(hardfork, blockNumber): boolean

Defined in: common.ts:495

Checks if set or provided hardfork is active on block number

Parameters

hardfork

string | null

Hardfork name or null (for HF set)

blockNumber

BigIntLike

Returns

boolean

True if HF is active on block number


hardforks()

hardforks(): HardforkTransitionConfig[]

Defined in: common.ts:768

Returns the hardfork definitions for the current chain.

Returns

HardforkTransitionConfig[]

Array of hardfork transition configs


hardforkTimestamp()

hardforkTimestamp(hardfork?): bigint | null

Defined in: common.ts:563

Returns the timestamp at which a given hardfork is scheduled (if any).

Parameters

hardfork?

string

Hardfork name, optional if HF set

Returns

bigint | null

Timestamp or null if the hardfork is not timestamp-based


isActivatedEIP()

isActivatedEIP(eip): boolean

Defined in: common.ts:482

Checks if an EIP is activated by either being included in the EIPs manually passed in with the CommonOpts.eips or in a hardfork currently being active

Note: this method only works for EIPs being supported by the CommonOpts.eips constructor option

Parameters

eip

number

Returns

boolean


nextHardforkBlockOrTimestamp()

nextHardforkBlockOrTimestamp(hardfork?): bigint | null

Defined in: common.ts:616

Returns the block number or timestamp at which the next hardfork will occur. For pre-merge hardforks, returns the block number. For post-merge hardforks, returns the timestamp. Returns null if there is no next hardfork.

Parameters

hardfork?

string

Hardfork name, optional if HF set

Returns

bigint | null

Block number or timestamp, or null if not available


param()

param(name): bigint

Defined in: common.ts:379

Returns a parameter for the current chain setup

If the parameter is present in an EIP, the EIP always takes precedence. Otherwise the parameter is taken from the latest applied HF with a change on the respective parameter.

Parameters

name

string

Parameter name (e.g. ‘minGasLimit’)

Returns

bigint

The value requested (throws if not found)


paramByBlock()

paramByBlock(name, blockNumber, timestamp?): bigint

Defined in: common.ts:449

Returns a parameter for the hardfork active on block number or optional provided total difficulty (Merge HF)

Parameters

name

string

Parameter name

blockNumber

BigIntLike

Block number

timestamp?

BigIntLike

Returns

bigint

The value requested or BigInt(0) if not found


paramByEIP()

paramByEIP(name, eip): bigint | undefined

Defined in: common.ts:429

Returns a parameter corresponding to an EIP

Parameters

name

string

Parameter name (e.g. ‘minGasLimit’ for ‘gasConfig’ topic)

eip

number

Number of the EIP

Returns

bigint | undefined

The value requested (throws if not found)


paramByHardfork()

paramByHardfork(name, hardfork): bigint

Defined in: common.ts:395

Returns the parameter corresponding to a hardfork

Parameters

name

string

Parameter name (e.g. ‘minGasLimit’)

hardfork

string

Hardfork name

Returns

bigint

The value requested (throws if not found)


resetParams()

resetParams(params): void

Defined in: common.ts:138

Fully resets the internal Common EIP params set with the values provided.

Example Format:

{
  1559: {
    initialBaseFee: 1000000000,
  }
}

Parameters

params

ParamsDict

Returns

void


setEIPs()

setEIPs(eips?): void

Defined in: common.ts:278

Sets the active EIPs

Parameters

eips?

number[] = []

Returns

void


setForkHashes()

setForkHashes(genesisHash): void

Defined in: common.ts:743

Sets any missing forkHashes on this Common instance.

Parameters

genesisHash

Uint8Array

The genesis block hash

Returns

void


setHardfork()

setHardfork(hardfork): void

Defined in: common.ts:147

Sets the hardfork to get params for

Parameters

hardfork

string

String identifier (e.g. ‘byzantium’) or Hardfork enum

Returns

void


setHardforkBy()

setHardforkBy(opts): string

Defined in: common.ts:255

Sets a new hardfork either based on block number (older HFs) or timestamp (Shanghai upwards).

Parameters

opts

HardforkByOpts

Block number or timestamp

Returns

string

The name of the HF set


updateParams()

updateParams(params): void

Defined in: common.ts:112

Update the internal Common EIP params set. Existing values will get preserved unless there is a new value for a parameter provided with params.

Example Format:

{
  1559: {
    initialBaseFee: 1000000000,
  }
}

Parameters

params

ParamsDict

Returns

void