ethereumjs-monorepo

@ethereumjs/common / Common

Class: Common

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

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

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Common(opts)

Parameters

Name Type
opts CommonOpts

Defined in

common.ts:237

Properties

DEFAULT_HARDFORK

Readonly DEFAULT_HARDFORK: string

Defined in

common.ts:55


customCrypto

Readonly customCrypto: CustomCrypto

Defined in

common.ts:62


events

events: EventEmitter

Defined in

common.ts:69

Methods

activeOnBlock

activeOnBlock(blockNumber): boolean

Alias to hardforkIsActiveOnBlock when hardfork is set

Parameters

Name Type
blockNumber BigIntLike

Returns

boolean

True if HF is active on block number

Defined in

common.ts:703


bootstrapNodes

bootstrapNodes(): BootstrapNodeConfig[]

Returns bootstrap nodes for the current chain

Returns

BootstrapNodeConfig[]

Dict with bootstrap nodes

Defined in

common.ts:975


chainId

chainId(): bigint

Returns the Id of current chain

Returns

bigint

chain Id

Defined in

common.ts:999


chainName

chainName(): string

Returns the name of current chain

Returns

string

chain name (lower case)

Defined in

common.ts:1007


consensusAlgorithm

consensusAlgorithm(): string

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

Defined in

common.ts:1056


consensusConfig

consensusConfig(): Object

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

Defined in

common.ts:1082


consensusType

consensusType(): string

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

Note: This value can update along a Hardfork.

Returns

string

Defined in

common.ts:1034


copy

copy(): Common

Returns a deep copy of this Common instance.

Returns

Common

Defined in

common.ts:1103


dnsNetworks

dnsNetworks(): string[]

Returns DNS networks for the current chain

Returns

string[]

Array of DNS ENR urls

Defined in

common.ts:983


eipBlock

eipBlock(eip): null | bigint

Returns the hardfork change block for eip

Parameters

Name Type Description
eip number EIP number

Returns

null | bigint

Block number or null if unscheduled

Defined in

common.ts:766


eipTimestamp

eipTimestamp(eip): null | bigint

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

Parameters

Name Type Description
eip number EIP number

Returns

null | bigint

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

Defined in

common.ts:784


eips

eips(): number[]

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

Returns

number[]

List of EIPs

Defined in

common.ts:1024


forkHash

forkHash(hardfork?, genesisHash?): string

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

Parameters

Name Type Description
hardfork? string Hardfork name, optional if HF set
genesisHash? Uint8Array Genesis block hash of the chain, optional if already defined and not needed to be calculated

Returns

string

Defined in

common.ts:905


genesis

genesis(): GenesisBlockConfig

Returns the Genesis parameters of the current chain

Returns

GenesisBlockConfig

Genesis dictionary

Defined in

common.ts:955


getHardforkBy

getHardforkBy(opts): string

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

An optional TD takes precedence in case the corresponding HF block is set to null or otherwise needs to match (if not an error will be thrown).

Parameters

Name Type
opts HardforkByOpts

Returns

string

The name of the HF

Defined in

common.ts:330


gteHardfork

gteHardfork(hardfork): boolean

Alias to hardforkGteHardfork when hardfork is set

Parameters

Name Type Description
hardfork string Hardfork name

Returns

boolean

True if hardfork set is greater than hardfork provided

Defined in

common.ts:734


hardfork

hardfork(): string

Returns the hardfork set

Returns

string

Hardfork name

Defined in

common.ts:991


hardforkBlock

hardforkBlock(hardfork?): null | bigint

Returns the hardfork change block for hardfork provided or set

Parameters

Name Type Description
hardfork? string Hardfork name, optional if HF set

Returns

null | bigint

Block number or null if unscheduled

Defined in

common.ts:743


hardforkForForkHash

hardforkForForkHash(forkHash): null | HardforkTransitionConfig

Parameters

Name Type Description
forkHash string Fork hash as a hex string

Returns

null | HardforkTransitionConfig

Array with hardfork data (name, block, forkHash)

Defined in

common.ts:927


hardforkGteHardfork

hardforkGteHardfork(hardfork1, hardfork2): boolean

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

Parameters

Name Type Description
hardfork1 null | string Hardfork name or null (if set)
hardfork2 string Hardfork name

Returns

boolean

True if HF1 gte HF2

Defined in

common.ts:714


hardforkIsActiveOnBlock

hardforkIsActiveOnBlock(hardfork, blockNumber): boolean

Checks if set or provided hardfork is active on block number

Parameters

Name Type Description
hardfork null | string Hardfork name or null (for HF set)
blockNumber BigIntLike  

Returns

boolean

True if HF is active on block number

Defined in

common.ts:688


hardforkTTD

hardforkTTD(hardfork?): null | bigint

Returns the hardfork change total difficulty (Merge HF) for hardfork provided or set

Parameters

Name Type Description
hardfork? string Hardfork name, optional if HF set

Returns

null | bigint

Total difficulty or null if no set

Defined in

common.ts:802


hardforkTimestamp

hardforkTimestamp(hardfork?): null | bigint

Parameters

Name Type
hardfork? string

Returns

null | bigint

Defined in

common.ts:752


hardforks

hardforks(): HardforkTransitionConfig[]

Returns the hardforks for current chain

Returns

HardforkTransitionConfig[]

Array with arrays of hardforks

Defined in

common.ts:963


isActivatedEIP

isActivatedEIP(eip): boolean

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

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

Parameters

Name Type
eip number

Returns

boolean

Defined in

common.ts:675


networkId

networkId(): bigint

Returns the Id of current network

Returns

bigint

network Id

Defined in

common.ts:1015


nextHardforkBlockOrTimestamp

nextHardforkBlockOrTimestamp(hardfork?): null | bigint

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

Parameters

Name Type Description
hardfork? string Hardfork name, optional if HF set

Returns

null | bigint

Block timestamp, number or null if not available

Defined in

common.ts:816


param

param(topic, name): bigint

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 Type Description
topic string Parameter topic (‘gasConfig’, ‘gasPrices’, ‘vm’, ‘pow’)
name string Parameter name (e.g. ‘minGasLimit’ for ‘gasConfig’ topic)

Returns

bigint

The value requested or BigInt(0) if not found

Defined in

common.ts:579


paramByBlock

paramByBlock(topic, name, blockNumber, td?, timestamp?): bigint

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

Parameters

Name Type Description
topic string Parameter topic
name string Parameter name
blockNumber BigIntLike Block number
td? BigIntLike Total difficulty *
timestamp? BigIntLike -

Returns

bigint

The value requested or BigInt(0) if not found

Defined in

common.ts:655


paramByEIP

paramByEIP(topic, name, eip): undefined | bigint

Returns a parameter corresponding to an EIP

Parameters

Name Type Description
topic string Parameter topic (‘gasConfig’, ‘gasPrices’, ‘vm’, ‘pow’)
name string Parameter name (e.g. ‘minGasLimit’ for ‘gasConfig’ topic)
eip number Number of the EIP

Returns

undefined | bigint

The value requested or undefined if not found

Defined in

common.ts:630


paramByHardfork

paramByHardfork(topic, name, hardfork): bigint

Returns the parameter corresponding to a hardfork

Parameters

Name Type Description
topic string Parameter topic (‘gasConfig’, ‘gasPrices’, ‘vm’, ‘pow’)
name string Parameter name (e.g. ‘minGasLimit’ for ‘gasConfig’ topic)
hardfork string Hardfork name

Returns

bigint

The value requested or BigInt(0) if not found

Defined in

common.ts:599


setChain

setChain(chain): ChainConfig

Sets the chain

Parameters

Name Type Description
chain string | number | bigint | object String (‘mainnet’) or Number (1) chain representation. Or, a Dictionary of chain parameters for a private network.

Returns

ChainConfig

The dictionary with parameters set as chain

Defined in

common.ts:270


setEIPs

setEIPs(eips?): void

Sets the active EIPs

Parameters

Name Type Default value
eips number[] []

Returns

void

Defined in

common.ts:469


setForkHashes

setForkHashes(genesisHash): void

Sets any missing forkHashes on the passed-in Common instance

Parameters

Name Type Description
genesisHash Uint8Array The genesis block hash

Returns

void

Defined in

common.ts:939


setHardfork

setHardfork(hardfork): void

Sets the hardfork to get params for

Parameters

Name Type Description
hardfork string String identifier (e.g. ‘byzantium’) or Hardfork enum

Returns

void

Defined in

common.ts:301


setHardforkBy

setHardforkBy(opts): string

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

An optional TD takes precedence in case the corresponding HF block is set to null or otherwise needs to match (if not an error will be thrown).

Parameters

Name Type
opts HardforkByOpts

Returns

string

The name of the HF set

Defined in

common.ts:446


custom

Static custom(chainParamsOrName, opts?): Common

Creates a Common object for a custom chain, based on a standard one.

It uses all the Chain parameters from the baseChain option except the ones overridden in a provided chainParamsOrName dictionary. Some usage example:

Common.custom({chainId: 123})

There are also selected supported custom chains which can be initialized by using one of the CustomChains for chainParamsOrName, e.g.:

Common.custom(CustomChains.MaticMumbai)

Note that these supported custom chains only provide some base parameters (usually the chain and network ID and a name) and can only be used for selected use cases (e.g. sending a tx with the @ethereumjs/tx library to a Layer-2 chain).

Parameters

Name Type Description
chainParamsOrName Partial<ChainConfig> | CustomChain Custom parameter dict (name will default to custom-chain) or string with name of a supported custom chain
opts CustomCommonOpts Custom chain options to set the baseChain, selected hardfork and others

Returns

Common

Defined in

common.ts:95


fromGethGenesis

Static fromGethGenesis(genesisJson, to): Common

Static method to load and set common from a geth genesis json

Parameters

Name Type Description
genesisJson any json of geth configuration
to GethConfigOpts further configure the common instance

Returns

Common

Common

Defined in

common.ts:186


getInitializedChains

Static getInitializedChains(customChains?): ChainsConfig

Parameters

Name Type
customChains? ChainConfig[]

Returns

ChainsConfig

Defined in

common.ts:1109


isSupportedChainId

Static isSupportedChainId(chainId): boolean

Static method to determine if a chainId is supported as a standard chain

Parameters

Name Type Description
chainId bigint bigint id (1) of a standard chain

Returns

boolean

boolean

Defined in

common.ts:209