Skip to content

Latest commit

 

History

History
884 lines (462 loc) · 16.7 KB

File metadata and controls

884 lines (462 loc) · 16.7 KB

@ethereumjs/common


@ethereumjs/common / Common

Class: Common

Defined in: common/src/common.ts:49

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

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

Use the createCommonFromGethGenesis constructor for creating a Common object from a Geth genesis file.

Constructors

Constructor

new Common(opts): Common

Defined in: common/src/common.ts:66

Parameters

opts

CommonOpts

Returns

Common

Properties

customCrypto

readonly customCrypto: CustomCrypto

Defined in: common/src/common.ts:57


DEFAULT_HARDFORK

readonly DEFAULT_HARDFORK: string

Defined in: common/src/common.ts:50


events

events: EventEmitter<CommonEvent>

Defined in: common/src/common.ts:64

Methods

activeOnBlock()

activeOnBlock(blockNumber): boolean

Defined in: common/src/common.ts:511

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/src/common.ts:788

Returns bootstrap nodes for the current chain.

Returns

BootstrapNodeConfig[]

Array of bootstrap node configs


chainId()

chainId(): bigint

Defined in: common/src/common.ts:812

Returns the Id of current chain

Returns

bigint

chain Id


chainName()

chainName(): string

Defined in: common/src/common.ts:820

Returns the name of current chain

Returns

string

chain name (lower case)


consensusAlgorithm()

consensusAlgorithm(): string

Defined in: common/src/common.ts:861

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/src/common.ts:887

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/src/common.ts:839

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/src/common.ts:908

Returns a deep copy of this Common instance.

Returns

Common


dnsNetworks()

dnsNetworks(): string[]

Defined in: common/src/common.ts:796

Returns DNS networks for the current chain

Returns

string[]

Array of DNS ENR urls


eipBlock()

eipBlock(eip): bigint | null

Defined in: common/src/common.ts:578

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/src/common.ts:829

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

Returns

number[]

List of EIPs


eipTimestamp()

eipTimestamp(eip): bigint | null

Defined in: common/src/common.ts:596

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/src/common.ts:712

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/src/common.ts:760

Returns the Genesis parameters of the current chain

Returns

GenesisBlockConfig

Genesis dictionary


getBlobGasSchedule()

getBlobGasSchedule(): BpoSchedule

Defined in: common/src/common.ts:459

Returns the blob gas schedule for the current hardfork

Returns

BpoSchedule

The blob gas schedule


getHardforkBy()

getHardforkBy(opts): string

Defined in: common/src/common.ts:173

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/src/common.ts:541

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/src/common.ts:804

Returns the hardfork set

Returns

string

Hardfork name


hardforkBlock()

hardforkBlock(hardfork?): bigint | null

Defined in: common/src/common.ts:550

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/src/common.ts:732

Parameters

forkHash

string

Fork hash as a hex string

Returns

HardforkTransitionConfig | null

Array with hardfork data (name, block, forkHash)


hardforkGteHardfork()

hardforkGteHardfork(hardfork1, hardfork2): boolean

Defined in: common/src/common.ts:521

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

Parameters

hardfork1

Hardfork name or null (if set)

string | null

hardfork2

string

Hardfork name

Returns

boolean

True if HF1 gte HF2


hardforkIsActiveOnBlock()

hardforkIsActiveOnBlock(hardfork, blockNumber): boolean

Defined in: common/src/common.ts:496

Checks if set or provided hardfork is active on block number

Parameters

hardfork

Hardfork name or null (for HF set)

string | null

blockNumber

BigIntLike

Returns

boolean

True if HF is active on block number


hardforks()

hardforks(): HardforkTransitionConfig[]

Defined in: common/src/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/src/common.ts:564

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/src/common.ts:483

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/src/common.ts:617

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/src/common.ts:380

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/src/common.ts:450

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/src/common.ts:430

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/src/common.ts:396

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/src/common.ts:139

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/src/common.ts:279

Sets the active EIPs

Parameters

eips

number[] = []

Returns

void


setForkHashes()

setForkHashes(genesisHash): void

Defined in: common/src/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/src/common.ts:148

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/src/common.ts:256

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/src/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