![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@ethereumjs/common
Advanced tools
Package description
@ethereumjs/common is a JavaScript library that provides common Ethereum constants, parameters, and functions. It is used to define and manage chain and hardfork parameters, making it easier to work with different Ethereum networks and their respective upgrades.
Chain and Hardfork Parameters
This feature allows you to define and manage chain and hardfork parameters. The code sample demonstrates how to create a Common instance for the Ethereum mainnet with the 'istanbul' hardfork.
const Common = require('@ethereumjs/common').default;
const mainnetCommon = new Common({ chain: 'mainnet', hardfork: 'istanbul' });
console.log(mainnetCommon.chainName()); // 'mainnet'
console.log(mainnetCommon.hardfork()); // 'istanbul'
Custom Chains
This feature allows you to define custom chain parameters. The code sample demonstrates how to create a Common instance for a custom chain with specific chain and network IDs.
const Common = require('@ethereumjs/common').default;
const customChainParams = { name: 'custom', chainId: 1234, networkId: 1234 };
const customCommon = Common.forCustomChain('mainnet', customChainParams, 'istanbul');
console.log(customCommon.chainId()); // 1234
EIP Activation
This feature allows you to check if a specific Ethereum Improvement Proposal (EIP) is activated for a given hardfork. The code sample demonstrates how to check if EIP-1559 is activated for the 'berlin' hardfork.
const Common = require('@ethereumjs/common').default;
const common = new Common({ chain: 'mainnet', hardfork: 'berlin' });
console.log(common.isActivatedEIP(1559)); // true or false depending on the EIP and hardfork
web3.js is a collection of libraries that allow you to interact with a local or remote Ethereum node using HTTP, IPC, or WebSocket. While it provides broader functionality for interacting with the Ethereum blockchain, it does not focus specifically on chain and hardfork parameters like @ethereumjs/common.
ethers.js is a library for interacting with the Ethereum blockchain and its ecosystem. It provides utilities for signing transactions, interacting with smart contracts, and more. Similar to web3.js, it offers a broader range of functionalities but does not specialize in chain and hardfork parameters.
ethjs is a highly modular, lightweight library for interacting with the Ethereum blockchain. It provides basic functionalities for sending transactions, interacting with contracts, and more. However, it does not offer the same level of detail for chain and hardfork parameters as @ethereumjs/common.
Readme
Resources common to all Ethereum implementations.
Succeeds the old ethereum/common library.
npm install ethereumjs-common
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({ chain: 'ropsten' })
c.param('gasPrices', 'ecAddGas', 'byzantium') // 500
// Chain and hardfork provided
c = new Common({ chain: 'ropsten', hardfork: '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({
chain: 'ropsten',
supportedHardforks: ['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.
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.
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
(DEFAULT_HARDFORK
)muirGlacier
The muirGlacier
HF delaying the difficulty bomb and scheduled for January 2020
is supported by the library since v1.5.0
.
For hardfork-specific parameter access with the param()
and paramByBlock()
functions
you can use the following topics
:
gasConfig
gasPrices
vm
pow
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!).
Supported chains:
mainnet
ropsten
rinkeby
kovan
goerli
(final configuration since v1.1.0
)The following chain-specific parameters are provided:
name
chainId
networkId
genesis
block header valueshardforks
block numbersbootstrapNodes
listTo 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.
There are two ways to set up a common instance with parameters for a private/custom chain:
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.
You can base your custom chain's config in a standard one, using the Common.forCustomChain
method.
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.
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
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.
FAQs
Resources common to all Ethereum implementations
The npm package @ethereumjs/common receives a total of 632,627 weekly downloads. As such, @ethereumjs/common popularity was classified as popular.
We found that @ethereumjs/common demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.