npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

evm-chainlist

v1.1.4

Published

This library for easy manage and access to EVM-based Chains information

Downloads

39

Readme

Chainlist

chainlist for easy manage and access to EVM-based Chains information License

Description

the project is a library for interacting with metadata of the Chain. It provides a set of functions for reading metadata to the chain object, managing listings.

when your project need maintain multiple chain or access the metadata of chains, chainlist can help you.

Features

  • Manage multiple chains
  • Compatible fields
  • Flexible access
  • Extensible
  • Autoload the config file of chains(only Node.js)

Installation

npm i evm-chainlist

or

yarn add evm-chainlist

Environment Variables

  • EVM_CHAINLIST_DISABLE_AUTOLOAD Disable autoload the data of chains, will export an empty instance of Chains. only Node.js environment
  • EVM_CHAINLIST_DATA_DIR This contains the path to the directory containing your chains files, them will be autoload to instance of Chains, default read process.cwd() + '/chains' directory, the file extension can be .json, .json5, .yaml, .yml, the chains data must includes name and chainId fields. only Node.js environment

Usage

We have some metadata for chains. you can find them here ethereum-lists/chains.

const ethereumMetadata = {
  "name": "Ethereum Mainnet",
  "chain": "ETH",
  "icon": "ethereum",
  "features": [{ "name": "EIP155" }, { "name": "EIP1559" }],
  "nativeCurrency": {
    "name": "Ether",
    "symbol": "ETH",
    "decimals": 18
  },
  "infoURL": "https://ethereum.org",
  "shortName": "eth",
  "chainId": 1,
  "networkId": 1,
  "code": "ethereum"
};

const rinkebyMetadata = {
  "name": "Rinkeby",
  "title": "Ethereum Testnet Rinkeby",
  "chain": "ETH",
  "nativeCurrency": {
    "name": "Rinkeby Ether",
    "symbol": "ETH",
    "decimals": 18
  },
  "infoURL": "https://www.rinkeby.io",
  "shortName": "rin",
  "chainId": 4,
  "networkId": 4,
  "status": "inactive"
};

const goerliMetadata = {
  "name": "Goerli",
  "title": "Ethereum Testnet Goerli",
  "chain": "ETH",
  "nativeCurrency": {
    "name": "Goerli Ether",
    "symbol": "ETH",
    "decimals": 18
  },
  "infoURL": "https://goerli.net/#about",
  "shortName": "gor",
  "chainId": 5,
  "networkId": 5,
  "testnet": true,
  "alias": {
    "internal": "goerli"
  }
};

Chain

It's like access ordinary JSON objects, but it provide index and useful methods

import { Chain } from 'evm-chainlist';

// Get ethereum
const ethereum = new Chain(ethereumMetadata);
const rinkeby = new Chain(rinkebyMetadata);
// Get goerli, and set indexes
const goerli = new Chain(goerliMetadata, {indexes: ['alias.internal']});

// Access metadata
console.log(ethereum.get('nativeCurrency.name')); // Output: Ether
console.log(ethereum.name); // Output: Ethereum Mainnet
console.log(ethereum.infoURL); // Output: https://ethereum.org
console.log(goerli.title); // Output: Ethereum Testnet Goerli

// Default indexes: name, chainId, networkId
console.log(goerli.equal('Ethereum Mainnet'); // Output: true
console.log(ethereum.equal(1); // Output: true
console.log(ethereum.equal('ethereum')); // Output: false

// Specify indexes
console.log(goerli.equal('goerli')); // Output: true
console.log(goerli.indexes()); // Output: ['alias.internal']
console.log(goerli.indexValues()); // Output: ['goerli']

// Provide methods
console.log(ethereum.isTestnet(), goerli.isTestnet()); // Output: false true
console.log(rinkeby.supportFeature('EIP155')); // Output: false
console.log(goerli.active(), rinkeby.inactive()); // Output: true true
// ...

ChainList

Some businesses only support some chains

import { ChainList } from 'evm-chainlist';

// Instantiate by Chain or metadata
const list = new ChainList([ethereumMetadata, rinkebyMetadata]);

// Add Chain
list.add(new Chain(goerliMetadata, {indexes: ['alias.internal']}));

// Access chain by index value
const ethereum = list.get(1);
console.log(ethereum.name); // Output: Ethereum Mainnet

const goerli = list.get('goerli');
console.log(goerli.name); // Output: Goerli

console.log(list.include(4)); // Output: true

// Del chain by index value
list.del('Rinkeby');

// ...

Chains

Global access all chain and list.

import { Chains } from 'evm-chainlist';

const data = [{
  "name": "Ethereum Mainnet",
  "chainId": 1
}, {
  "name": "OP Mainnet", 
  "chainId": 10
}, {
  "name": "Binance Smart Chain",
  "chainId": 56
}, {
  "name": "Kovan",
  "chainId": 42
}, {
  "name": "Rinkeby",
  "chainId": 4
}];

// Instantiate by Chain or metadata
const chains = new Chains(data, {lists: {
  'business1': [1, 56, 5],
}});

// Add Chain
chains.addChain(new Chain({
  "name": "Goerli",
  "chainId": 5,
  "alias": {
    "internal": "goerli"
  }
}, {indexes: ['alias.internal']}));

const rinkeby = chains.getChain(4);
console.log(rinkeby.name); // Output: Rinkeby

// Add ChainList
chains.addChainList('test', ['goerli', 42]);

// Access ChainList
const testList = chains.getChainList('test');
console.log(testList.include(5)); // Output: true

// ...

This module will autoload the chains data and export the instance of Chains;

import chains, { Chains } from 'evm-chainlist';
// import defaults the instance of Chains through auto load your project 'chains' directory

console.log(chains instanceof Chinas);  // Output: true

Contributing

Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request. Make sure to read the contribution guidelines before getting started.

License

This project is licensed under the MIT License.