eip155-chains
v0.1.3
Published
Aggregate all eip155 chains from multiple sources in one place.
Downloads
479
Maintainers
Readme
eip155-chains
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:
- npm package
eth-chains
- chainid.network and cached it in repo
Rpc nodes sources:
- viem chains definition
- chainid.network
- 1rpc
- flashbots