ethereumjs-common

  • Version 1.5.2
  • Published
  • 795 kB
  • No dependencies
  • MIT license

Install

npm i ethereumjs-common
yarn add ethereumjs-common
pnpm add ethereumjs-common

Overview

Resources common to all Ethereum implementations

Index

Classes

class Common

class Common {}
  • Common class to access chain and hardfork parameters

constructor

constructor(
chain: string | number | object,
hardfork?: string,
supportedHardforks?: string[]
);
  • Parameter chain

    String ('mainnet') or Number (1) chain

    Parameter hardfork

    String identifier ('byzantium') for hardfork (optional)

    Parameter supportedHardforks

    Limit parameter returns to the given hardforks (optional)

method activeHardfork

activeHardfork: (blockNumber?: number | null, opts?: hardforkOptions) => string;
  • Returns the latest active hardfork name for chain or block or throws if unavailable

    Parameter blockNumber

    up to block if provided, otherwise for the whole chain

    Parameter opts

    Hardfork options (onlyActive unused) Hardfork name

method activeHardforks

activeHardforks: (
blockNumber?: number | null,
opts?: hardforkOptions
) => Array<any>;
  • Returns the active hardfork switches for the current chain

    Parameter blockNumber

    up to block if provided, otherwise for the whole chain

    Parameter opts

    Hardfork options (onlyActive unused) Array with hardfork arrays

method activeOnBlock

activeOnBlock: (blockNumber: number, opts?: hardforkOptions) => boolean;
  • Alias to hardforkIsActiveOnBlock when hardfork is set

    Parameter blockNumber

    Parameter opts

    Hardfork options (onlyActive unused)

    Returns

    True if HF is active on block number

method bootstrapNodes

bootstrapNodes: () => any;
  • Returns bootstrap nodes for the current chain

    Returns

    {Dictionary} Dict with bootstrap nodes

method chainId

chainId: () => number;
  • Returns the Id of current chain

    Returns

    chain Id

method chainName

chainName: () => string;
  • Returns the name of current chain

    Returns

    chain name (lower case)

method consensus

consensus: (hardfork?: string) => string;
  • Provide the consensus type for the hardfork set or provided as param

    Parameter hardfork

    Hardfork name, optional if hardfork set

    Returns

    Consensus type (e.g. 'pow', 'poa')

method finality

finality: (hardfork?: string) => string;
  • Provide the finality type for the hardfork set or provided as param

    Parameter hardfork

    Hardfork name, optional if hardfork set

    Returns

    {String} Finality type (e.g. 'pos', null of no finality)

method forCustomChain

static forCustomChain: (
baseChain: string | number,
customChainParams: Partial<Chain>,
hardfork?: string | null,
supportedHardforks?: Array<string>
) => Common;
  • Creates a Common object for a custom chain, based on a standard one. It uses all the [[Chain]] params from [[baseChain]] except the ones overridden in [[customChainParams]].

    Parameter baseChain

    The name (mainnet) or id (1) of a standard chain used to base the custom chain params on.

    Parameter customChainParams

    The custom parameters of the chain.

    Parameter hardfork

    String identifier ('byzantium') for hardfork (optional)

    Parameter supportedHardforks

    Limit parameter returns to the given hardforks (optional)

method genesis

genesis: () => any;
  • Returns the Genesis parameters of current chain

    Returns

    Genesis dictionary

method gteHardfork

gteHardfork: (hardfork: string, opts?: hardforkOptions) => boolean;
  • Alias to hardforkGteHardfork when hardfork is set

    Parameter hardfork

    Hardfork name

    Parameter opts

    Hardfork options

    Returns

    True if hardfork set is greater than hardfork provided

method hardfork

hardfork: () => string | null;
  • Returns the hardfork set

    Returns

    Hardfork name

method hardforkBlock

hardforkBlock: (hardfork?: string) => number;
  • Returns the hardfork change block for hardfork provided or set

    Parameter hardfork

    Hardfork name, optional if HF set

    Returns

    Block number

method hardforkGteHardfork

hardforkGteHardfork: (
hardfork1: string | null,
hardfork2: string,
opts?: hardforkOptions
) => boolean;
  • Sequence based check if given or set HF1 is greater than or equal HF2

    Parameter hardfork1

    Hardfork name or null (if set)

    Parameter hardfork2

    Hardfork name

    Parameter opts

    Hardfork options

    Returns

    True if HF1 gte HF2

method hardforkIsActiveOnBlock

hardforkIsActiveOnBlock: (
hardfork: string | null,
blockNumber: number,
opts?: hardforkOptions
) => boolean;
  • Checks if set or provided hardfork is active on block number

    Parameter hardfork

    Hardfork name or null (for HF set)

    Parameter blockNumber

    Parameter opts

    Hardfork options (onlyActive unused)

    Returns

    True if HF is active on block number

method hardforkIsActiveOnChain

hardforkIsActiveOnChain: (
hardfork?: string | null,
opts?: hardforkOptions
) => boolean;
  • Checks if given or set hardfork is active on the chain

    Parameter hardfork

    Hardfork name, optional if HF set

    Parameter opts

    Hardfork options (onlyActive unused)

    Returns

    True if hardfork is active on the chain

method hardforks

hardforks: () => any;
  • Returns the hardforks for current chain

    Returns

    {Array} Array with arrays of hardforks

method isHardforkBlock

isHardforkBlock: (blockNumber: number, hardfork?: string) => boolean;
  • True if block number provided is the hardfork (given or set) change block of the current chain

    Parameter blockNumber

    Number of the block to check

    Parameter hardfork

    Hardfork name, optional if HF set

    Returns

    True if blockNumber is HF block

method networkId

networkId: () => number;
  • Returns the Id of current network

    Returns

    network Id

method param

param: (topic: string, name: string, hardfork?: string) => any;
  • Returns the parameter corresponding to a hardfork

    Parameter topic

    Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding')

    Parameter name

    Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)

    Parameter hardfork

    Hardfork name, optional if hardfork set

method paramByBlock

paramByBlock: (topic: string, name: string, blockNumber: number) => any;
  • Returns a parameter for the hardfork active on block number

    Parameter topic

    Parameter topic

    Parameter name

    Parameter name

    Parameter blockNumber

    Block number

method setChain

setChain: (chain: string | number | object) => any;
  • Sets the chain

    Parameter chain

    String ('mainnet') or Number (1) chain representation. Or, a Dictionary of chain parameters for a private network.

    Returns

    The dictionary with parameters set as chain

method setHardfork

setHardfork: (hardfork: string | null) => void;
  • Sets the hardfork to get params for

    Parameter hardfork

    String identifier ('byzantium')

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (16)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ethereumjs-common.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/ethereumjs-common)
  • HTML
    <a href="https://www.jsdocs.io/package/ethereumjs-common"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>