From 45dcd617eb1dbe87494b01e299d6573912e683c3 Mon Sep 17 00:00:00 2001 From: Taylor Dawson Date: Fri, 28 May 2021 12:03:18 -0400 Subject: [PATCH] 0.2.1: (feat) Update readme + add types --- README.md | 46 +++++++++++++++++++++++++++++++++++++++------- index.ts | 2 +- package.json | 2 +- src/index.ts | 4 ++-- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 83cdc7d..d8e134a 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,50 @@ +# Eth Chains +Helper module for getting Ethereum chains info from [chainid.network](https://chainid.network/). -### Usage -```js -import chains, { ChainId, ChainName } from 'eth-chains' +## Install +``` +yarn add eth-chains +``` -chains.getById(ChainId.EthereumMainnet) // returns Ethereum Mainnet object -chains.getByName(ChainName.EthereumMainnet) -chains.get() // pass in a networkId or a networkName +``` +npm install eth-chains +``` +## Usage +Import `chains` methods and enums: +```ts +import chains, { ChainId, ChainName } from 'eth-chains' +``` +### Chain names and ids via Enums: +```ts console.log(ChainId.EthereumMainnet) // 1 console.log(ChainId.BinanceSmartChainMainnet) // 56 - console.log(ChainName.EthereumMainnet) // "Ethereum Mainnet" ``` +### Chain by ID: +```ts +chains.getById(ChainId.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" } +// Equivalent +chains.getById(1) +``` + +### Chain by Name: +```ts +chains.getByName(ChainName.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" } +// Equivalent +chains.getByName('Ethereum Mainnet') +``` + +### Typescript Types: +```ts +import { Chain, NativeCurrency, Explorer } 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 diff --git a/index.ts b/index.ts index c45768b..b2027d7 100644 --- a/index.ts +++ b/index.ts @@ -1 +1 @@ -export {default as chains} from './src' \ No newline at end of file +export {default as chains, Chain, ChainId, ChainName, NativeCurrency, Explorer } from './src' \ No newline at end of file diff --git a/package.json b/package.json index 1bdd104..812d866 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eth-chains", - "version": "0.2.0", + "version": "0.2.1", "description": "Helper module for getting Ethereum chains info.", "main": "index.ts", "author": "Taylor Dawson", diff --git a/src/index.ts b/src/index.ts index 414cf5c..dbe3042 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ import { Chain } from './types' import { chains } from './chains' - +export { NativeCurrency, Explorer } from './types' export { ChainName, ChainId } from './enums' -export { chains } +export { chains, Chain } const getById = (id: number): Chain | undefined => chains[id]