Skip to content

Commit

Permalink
0.2.1: (feat) Update readme + add types
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorjdawson committed May 28, 2021
1 parent c3fb465 commit 45dcd61
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {default as chains} from './src'
export {default as chains, Chain, ChainId, ChainName, NativeCurrency, Explorer } from './src'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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]

Expand Down

0 comments on commit 45dcd61

Please sign in to comment.