Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

int4js-common

int4js9MIT4.0.0TypeScript support: included

Resources common to all INTChain implementations

intchain, int4js, constants, parameters, genesis, networks, bootstrap

readme

SYNOPSIS

NPM Package Build Status Actions Status Coverage Status JavaScript Style Guide Gitter

ETHEREUMJS-COMMON

Resources common to all Ethereum implementations

Succeeds the old ethereum/common library.

INSTALL

npm install ethereumjs-common

USAGE

All parameters can be accessed through the Common class which can be required through the main package and instantiated either with just the chain (e.g. 'mainnet') or the chain together with a specific hardfork provided.

Here are some simple usage examples:

const Common = require('ethereumjs-common')

// Instantiate with only the chain
let c = new Common('ropsten')
c.param('gasPrices', 'ecAddGas', 'byzantium') // 500

// Chain and hardfork provided
c = new Common('ropsten', 'byzantium')
c.param('pow', 'minerReward') // 3000000000000000000

// Access genesis data for Ropsten network
c.genesis().hash // 0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d

// Get bootstrap nodes for chain/network
c.bootstrapNodes() // Array with current nodes

It is encouraged to also explicitly set the supportedHardforks if the initializing library only supports a certain range of hardforks:

let c = new Common('ropsten', null, ['byzantium', 'constantinople', 'petersburg'])

This will e.g. throw an error when a param is requested for an unsupported hardfork and like this prevents unpredicted behaviour.

API

See the API documentation for a full list of functions for accessing specific chain and depending hardfork parameters. There are also additional helper functions like paramByBlock (topic, name, blockNumber) or hardforkIsActiveOnBlock (hardfork, blockNumber) to ease blockNumber based access to parameters.

Hardfork Params

Active Hardforks

There are currently parameter changes by the following past and future hardfork by the library supported:

  • chainstart
  • homestead
  • dao
  • tangerineWhistle
  • spuriousDragon
  • byzantium
  • constantinople
  • petersburg (aka constantinopleFix, apply together with constantinople)
  • istanbul
  • muirGlacier

Future Hardforks

The muirGlacier HF delaying the difficulty bomb and scheduled for January 2020 is supported by the library since v1.5.0.

Parameter Access

For hardfork-specific parameter access with the param() and paramByBlock() functions you can use the following topics:

  • gasConfig
  • gasPrices
  • vm
  • pow
  • casper
  • sharding

See one of the hardfork files like byzantium.json in the hardforks directory for an overview. For consistency, the chain start (chainstart) is considered an own hardfork.

The hardfork-specific json files only contain the deltas from chainstart and shouldn't be accessed directly until you have a specific reason for it.

Note: The list of gasPrices and gas price changes on hardforks is consistent but not complete, so there are currently gas price values missing (PRs welcome!).

Chain Params

Supported chains:

  • mainnet
  • ropsten
  • rinkeby
  • kovan
  • goerli (final configuration since v1.1.0)
  • Private/custom chain parameters

The following chain-specific parameters are provided:

  • name
  • chainId
  • networkId
  • genesis block header values
  • hardforks block numbers
  • bootstrapNodes list

To get an overview of the different parameters have a look at one of the chain-specifc files like mainnet.json in the chains directory, or to the Chain type in ./src/types.ts.

Working with private/custom chains

There are two ways to set up a common instance with parameters for a private/custom chain:

  1. You can pass a dictionary - conforming to the parameter format described above - with your custom values in the constructor or the setChain() method for the chain parameter.

  2. You can base your custom chain's config in a standard one, using the Common.forCustomChain method.

Bootstrap Nodes

There is no separate config file for bootstrap nodes like in the old ethereum-common library. Instead use the common.bootstrapNodes() function to get nodes for a specific chain/network.

Genesis States

Network-specific genesis files are located in the genesisStates folder.

Due to the large file sizes genesis states are not directly included in the index.js file but have to be accessed directly, e.g.:

const mainnetGenesisState = require('ethereumjs-common/dist/genesisStates/mainnet')

Or by accessing dynamically:

const genesisStates = require('ethereumjs-common/dist/genesisStates')
const mainnetGenesisState = genesisStates.genesisStateByName('mainnet')
const mainnetGenesisState = genesisStates.genesisStateById(1) // alternative via network Id

EthereumJS

See our organizational documentation for an introduction to EthereumJS as well as information on current standards and best practices.

If you want to join for work or do improvements on the libraries have a look at our contribution guidelines.

LICENSE

MIT

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog (modification: no type change headlines) and this project adheres to Semantic Versioning.

1.5.0 - 2019-12-10

Support for the MuirGlacier HF (EIP-2387) scheduled for January 2020 delaying the difficulty bomb.

Changes:

  • Implemented EIP-2384 Difficulty Bomb Delay, PR #75
  • Consistent genesis account balance format, converted from decimal to hex where necessary, PR #73

1.4.0 - 2019-11-05

First release with full Istanbul support regarding parameter introductions/updates and HF block numbers set for supported chains.

Relevant PRs:

  • Added Istanbul block numbers for mainnet, goerli and rinkeby, PR #68
  • Added Petersburg and Constantinople fork blocks to rinkeby, PR #71
  • Added EIP-2200 (rebalance net-metered SSTORE gas costs) parameters for Istanbul, PR #65

Other noteworthy changes:

  • Adding forks (including Istanbul) for kovan, PR #70
  • Fixed kovan genesis state, PR #66

1.3.2 - 2019-09-04

Istanbul Updates:

  • Added gas parameters for EIP-2200 (rebalanced net-metered SSTORE gas costs), PR #65
  • Renamed hardfork blake2bRound (-> blake2Round) parameter, PR #63

Other Changes:

  • Fixed Kovan genesis state, PR #66

1.3.1 - 2019-08-08

Added missing Istanbul gas costs for:

  • ChainID opcode (EIP-1344, as base param in hardforks/chainstart.json)
  • Blake2b precompile (EIP-2129/152)
  • Calldata gas cost reduction (EIP-2028)

See PR #58.

1.3.0 - 2019-06-18

  • Add a static factory method Custom.forCustomChain to make working with custom/private chains easier.

1.2.1 - 2019-06-03

  • Added Istanbul HF candidate EIP-1108 (DRAFT) updated alt_bn128 precompile gas costs (see hardforks/istanbul.json)

1.2.0 - 2019-05-27

DRAFT Istanbul Hardfork Support

Draft support for the upcoming Istanbul hardfork planned for October 2019, use istanbul as constructor hardfork parameter to activate. Parameters relevant to new EIPs accepted for the HF will be added along subsequent 1.2.x releases, the finalized HF version will be released along a subsequent 1.x.0 release (likely 1.3.0).

See new hardforks/istanbul.json file as well as PR #51.

1.1.0 - 2019-02-04

Petersburg Hardfork Support

This release now supports the new Petersburg (aka constantinopleFix) HF removing support for EIP 1283. Petersburg is conceptualized within the library as a separate delta-containing HF, only removing EIP 1283 support and containing nothing else. It should therefore always be applied together with the Constantinople HF, either by using the same block number to update on both (mainnet scenario) or applying subsequently on subsequent block numbers (ropsten scenario).

HF related changes (from PR #44):

  • New hardforks/petersburg.json HF file
  • constantinople and petersburg block numbers for ropsten and mainnet
  • Updated tests, new petersburg related tests

Launched/Final Goerli Configuration Support

The release now supports the final Goerli cross-client testnet configuration.

Goerli related changes (from PR #48):

  • Updated chains/goerli.json configuration file (chainId -> 5, networkId -> 5, genesis parameters)
  • HF block numbers up to petersburg hardfork
  • Updated bootstrap nodes
  • Updated genesisStates/goerli.json genesis state
  • Test updates

Other Changes

  • Fixed a bug in hardforkGteHardfork() where non-active hardforks were considered equal to chainstart when onlyActive is passed, see PR #44
  • Use CLI scripts from ethereumjs-config in package.json, PR #43

1.0.0 - 2019-01-23

First TypeScript based release of the library (for details see PR #38), so release coming with type declaration files and additional type safety! 😄

Breaking Changes

Library Import

TypeScript handles ES6 transpilation a bit differently (at the end: cleaner) than babel so require syntax of the library slightly changes to:

const Common = require('ethereumjs-common').default

Genesis State Import/Usage

Import path and usage API of genesis state has changed, see also the docs on this, PR #39:

const mainnetGenesisState = require('ethereumjs-common/dist/genesisStates/mainnet')

Or by accessing dynamically:

const genesisStates = require('ethereumjs-common/dist/genesisStates')
const mainnetGenesisState = genesisStates.genesisStateByName('mainnet')
const mainnetGenesisState = genesisStates.genesisStateById(1) // alternative via network Id

Removed hybridCasper (draft) hardfork

Not likely that anyone has used this, but just in case: The once anticipated hybridCasper (draft) hardfork has been removed from the list of hardforks, see PR #37

0.6.1 - 2018-11-28

  • Experimental support for the Goerli cross-client PoA testnet (chains/goerli.json), see PR #31
  • Unified hex-prefixing (so always prefixing with 0x) of account addresses in genesis files (fixes an issue with state root computation on other libraries), see PR #32

0.6.0 - 2018-10-11

Parameter support for the Constantinople hardfork (see hardforks/constantinople.json):

  • Added SSTORE gas/refund prices (EIP-1283), PR #27
  • Added Block Reward Adjustment (EIP-1234), PR #26

0.5.0 - 2018-08-27

  • Introduces support for private chains by allowing to pass a custom dictionary as the chain parameter in the constructor or the setChain() method as an alternative to just passing one of the predefined chain String names (e.g. mainnet, ropsten), PR #24

0.4.1 - 2018-08-13

  • Added timestamp field to genesis definitions in chain files, set for Rinkeby and null for other chains, PR #21
  • Updated Ropsten bootstrap nodes, PR #20

0.4.0 - 2018-06-20

  • Remove leftover ...Gas postfix for some gas prices (e.g. ecAddGas -> ecAdd) to be consistent with overall gas price naming

0.3.1 - 2018-05-28

  • Added two alias functions activeOnBlock() and gteHardfork() when hardfork is set for convenience, PR #15
  • Added option to dynamically choose genesis state (see README), PR #15

0.3.0 - 2018-05-25

  • Allow functions like hardforkIsActiveOnBlock() - where hardfork is provided as param - also to be run on hardfork set for greater flexibility/comfort, PR #13
  • New hardforkGteHardfork() method for HF order comparisons, PR #13

0.2.0 - 2018-05-14

  • New optional initialization parameter allowedHardforks, this allows for cleaner client library implementations by preventing undefined behaviour, PR #10
  • Added activeHardfork() function to get latest active HF for chain or block, PR #11

0.1.1 - 2018-05-09

  • Remove dynamic require to prevent browserify issue, PR #8

0.1.0 - 2018-05-09

  • Initial version, this library succeeds the ethereum/common library, being more future-proof through a better structured design

Features:

  • Easy chain-/HF-based parameter access
  • No parameter changes on library updates (c.param('gasPrices', 'ecAddGas', 'byzantium') will always return the same value)
  • Ease experimentation/research by allowing to include future HF parameters (already included as draft: constantinople and hybridCasper) without breaking current installations
  • Improved structure for parameter access (mainly through topics like gasPrices, pow, sharding) for better readability/developer overview
  • See README and API Docs for a more in-depth feature overview and usage instructions