0.1.3 • Published 1 year ago

eip155-chains v0.1.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

eip155-chains

npm package Build Status Downloads Issues Code Coverage Commitizen Friendly Semantic Release

Aggregate all eip155 chains from multiple sources in one place.

Usage

import { ethers } from 'ethers';
import { getChainById, getEthersProvider } from 'eip155-chains';

const options = {
  apiKey: {
    INFURA_API_KEY: 'Your INFURA_API_KEY',
    ALCHEMY_API_KEY: 'Your ALCHEMY_API_KEY'
  },
  healthyCheckEnabled: true,
  filters: {
    features: ['privacy']
  }
}

const chainInfo = await getChainById(chainId, options)
console.log(`rpcs: `, chainInfo.rpc)
console.log(`classifiedRpc.https: ${chainInfo.classifiedRpc.https}`)

// You can use https only
const providers = chainInfo.classifiedRpc.https.map(rpc => new ethers.JsonRpcProvider(rpc.url))

// or setup provider according to protocol
const providers = chainInfo.rpc.map(url => {
  if (jsonRpcProvider && url.startsWith("http://") || url.startsWith("https://")) {
    return new jsonRpcProvider(url)
  } else /** if (wsRpcProvider && url.startsWith("ws://") || url.startsWith("wss://")) */ {
    return new wsRpcProvider(url)
  }
})

const provider = new ethers.FallbackProvider(providers)

// or using getEthersProvider
const [provider, stop] = await getEthersProvider(chainId, options)

const blockNumber = await provider.getBlockNumber()
console.log(blockNumber)

// Don't forget release provider
await stop()

Sources

EIP155ChainInfo sources:

Rpc nodes sources:

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago