dann254 / eth-chains

Helper module for getting Ethereum chains info from chainid.network.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Publish npm

Eth Chains

Helper module for getting Ethereum chains info from chainid.network.

Install

yarn add eth-chains
npm install eth-chains

Usage

Import chains methods and enums:

import chains, { ChainId, ChainName } from 'eth-chains'

Chain names and ids via Enums:

console.log(ChainId.EthereumMainnet) // 1
console.log(ChainId.BinanceSmartChainMainnet) // 56
console.log(ChainName.EthereumMainnet) // "Ethereum Mainnet"

Chain by ID:

chains.getById(ChainId.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
// Equivalent
chains.getById(1) 

Chain by Name:

chains.getByName(ChainName.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
// Equivalent
chains.getByName('Ethereum Mainnet')

Chain List

import { chainList, Chains } from 'eth-chains'
const evmChains: Chains = chainList

console.log(evmChains)

Typescript Types:

import { Chain, NativeCurrency, Explorer, Chains } from 'eth-chains'
const ethereum: Chain = chains.getById(ChainId.EthereumMainnet)
ethereum.chain // 'ETH'

TODO:

  • Add webhook that watches the chains repo and triggers an update to this package whenever that repo gets updated
    • Add check in the deploy script to make sure that the types are correct before publishing
  • Add Tests
    • Once quicktype is added, test with different chains.json objects to make sure it can handle new types
  • Use quicktype to autogen types from json
  • Autogen Chain Id enum
  • Autogen Chain Name enum

About

Helper module for getting Ethereum chains info from chainid.network.


Languages

Language:TypeScript 100.0%