import {ethers} from "ethers"; const providers = {} // indexed by chain id export function provider(chainId) { let result = providers[chainId] if( result === undefined ) { const rpc_url = process.env['DEXORDER_RPC_URL_'+chainId] if( rpc_url === undefined ) { console.error('No provider found for chainId',chainId) return null } result = rpc_url.startsWith('ws') ? new ethers.WebSocketProvider(rpc_url, chainId) : new ethers.JsonRpcProvider(rpc_url, chainId) providers[chainId] = result } return result }