ethereumjs-monorepo

@ethereumjs/common


@ethereumjs/common / Common

Class: Common

Defined in: common.ts:45

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

Use the Common.custom static constructor for creating simple custom chain Common objects (more complete custom chain setups can be created via the main constructor).

Constructors

Constructor

new Common(opts): Common

Defined in: common.ts:62

Parameters

opts

CommonOpts

Returns

Common

Properties

customCrypto

readonly customCrypto: CustomCrypto

Defined in: common.ts:53


DEFAULT_HARDFORK

readonly DEFAULT_HARDFORK: string

Defined in: common.ts:46


events

events: EventEmitter<CommonEvent>

Defined in: common.ts:60

Methods

activeOnBlock()

activeOnBlock(blockNumber): boolean

Defined in: common.ts:472

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:729

Returns bootstrap nodes for the current chain

Returns

BootstrapNodeConfig[]

Dict with bootstrap nodes


chainId()

chainId(): bigint

Defined in: common.ts:753

Returns the Id of current chain

Returns

bigint

chain Id


chainName()

chainName(): string

Defined in: common.ts:761

Returns the name of current chain

Returns

string

chain name (lower case)


consensusAlgorithm()

consensusAlgorithm(): string

Defined in: common.ts:802

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:828

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:780

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:849

Returns a deep copy of this Common instance.

Returns

Common


dnsNetworks()

dnsNetworks(): string[]

Defined in: common.ts:737

Returns DNS networks for the current chain

Returns

string[]

Array of DNS ENR urls


eipBlock()

eipBlock(eip): null | bigint

Defined in: common.ts:535

Returns the hardfork change block for eip

Parameters

eip

number

EIP number

Returns

null | bigint

Block number or null if unscheduled


eips()

eips(): number[]

Defined in: common.ts:770

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

Returns

number[]

List of EIPs


eipTimestamp()

eipTimestamp(eip): null | bigint

Defined in: common.ts:553

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

Parameters

eip

number

EIP number

Returns

null | bigint

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:660

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}`


genesis()

genesis(): GenesisBlockConfig

Defined in: common.ts:709

Returns the Genesis parameters of the current chain

Returns

GenesisBlockConfig

Genesis dictionary


getHardforkBy()

getHardforkBy(opts): string

Defined in: common.ts:169

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

Parameters

opts

HardforkByOpts

Returns

string

The name of the HF


gteHardfork()

gteHardfork(hardfork): boolean

Defined in: common.ts:503

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:745

Returns the hardfork set

Returns

string

Hardfork name


hardforkBlock()

hardforkBlock(hardfork?): null | bigint

Defined in: common.ts:512

Returns the hardfork change block for hardfork provided or set

Parameters

hardfork?

string

Hardfork name, optional if HF set

Returns

null | bigint

Block number or null if unscheduled


hardforkForForkHash()

hardforkForForkHash(forkHash): null | HardforkTransitionConfig

Defined in: common.ts:680

Parameters

forkHash

string

Fork hash as a hex string

Returns

null | HardforkTransitionConfig

Array with hardfork data (name, block, forkHash)


hardforkGteHardfork()

hardforkGteHardfork(hardfork1, hardfork2): boolean

Defined in: common.ts:483

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

Parameters

hardfork1

Hardfork name or null (if set)

null string
hardfork2

string

Hardfork name

Returns

boolean

True if HF1 gte HF2


hardforkIsActiveOnBlock()

hardforkIsActiveOnBlock(hardfork, blockNumber): boolean

Defined in: common.ts:457

Checks if set or provided hardfork is active on block number

Parameters

hardfork

Hardfork name or null (for HF set)

null string
blockNumber

BigIntLike

Returns

boolean

True if HF is active on block number


hardforks()

hardforks(): HardforkTransitionConfig[]

Defined in: common.ts:717

Returns the hardforks for current chain

Returns

HardforkTransitionConfig[]

Array with arrays of hardforks


hardforkTimestamp()

hardforkTimestamp(hardfork?): null | bigint

Defined in: common.ts:521

Parameters

hardfork?

string

Returns

null | bigint


isActivatedEIP()

isActivatedEIP(eip): boolean

Defined in: common.ts:444

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?): null | bigint

Defined in: common.ts:571

Returns the change block for the next hardfork after the hardfork provided or set

Parameters

hardfork?

string

Hardfork name, optional if HF set

Returns

null | bigint

Block timestamp, number or null if not available


param()

param(name): bigint

Defined in: common.ts:360

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:430

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): undefined | bigint

Defined in: common.ts:410

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

undefined | bigint

The value requested (throws if not found)


paramByHardfork()

paramByHardfork(name, hardfork): bigint

Defined in: common.ts:376

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:135

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:275

Sets the active EIPs

Parameters

eips

number[] = []

Returns

void


setForkHashes()

setForkHashes(genesisHash): void

Defined in: common.ts:692

Sets any missing forkHashes on the passed-in Common instance

Parameters

genesisHash

Uint8Array

The genesis block hash

Returns

void


setHardfork()

setHardfork(hardfork): void

Defined in: common.ts:144

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:252

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

Parameters

opts

HardforkByOpts

Returns

string

The name of the HF set


updateParams()

updateParams(params): void

Defined in: common.ts:108

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