web3networks is a library for managing blockchain networks, allowing you to add networks, query networks, and obtain a list of networks.
You can install the package either using NPM or using Yarn
npm install @loxjs/web3networksyarn add @loxjs/web3networksIn web3networks, the data structure for a network is as follows:
{
"chainId": 1,
// Chain Type
"chain": "Ethereum",
// Chain Name
"name": "Ethereum",
"rpcUrl": "https://ethereum-rpc.publicnode.com",
"blockExplorerUrl": "https://etherscan.io/",
// Whether it is a test network
"isTest": false,
// Native currency of the network
"currency": {
"name": "ETH",
"symbol": "ETH",
"decimals": 18
},
// Default configurations for executing transactions on the current network
"options": {
// Default gas limit
"defaultGasLimit": 3000000,
// Default gas price, in gwei
"defaultGasPrice": "1",
// Default gas price multiplier, used to set the gas price of a transaction by
// multiplying the real-time gas price from the blockchain with this multiplier
"defaultMultiplierForGasPrice": 1.5
}
}
Usage:
const web3networks = require('@loxjs/web3networks')
// Get all networks
const networks = web3networks.list
// Add a new network
web3networks.addNetwork({...})
// Use chainId to get a network
const network = web3networks.getNetworkByChainId(chainId)