web3-react
web3-react copied to clipboard
Error handling when using multiple RPC endpoints on @web3-react/network v8.0.14-beta.0
Hi there, I'm trying to use @web3-react v8 on my application to provide a set of RPC endpoints as backup in case something happens to one of them. I'm following the pattern provided in the Nextjs example, chians.ts:
export const CHAINS = {
1: {
urls: [
process.env.REACT_APP_INFURA_KEY ? `https://mainnet.infura.io/v3/5${process.env.REACT_APP_INFURA_KEY}` : undefined,
process.env.REACT_APP_ALCHEMY_KEY
? `https://eth-mainnet.alchemyapi.io/v2/${process.env.REACT_APP_ALCHEMY_KEY}`
: undefined,
process.env.REACT_APP_POCKET_KEY
? `https://eth-mainnet.gateway.pokt.network/v1/lb/${process.env.REACT_APP_POCKET_KEY}`
: undefined,
].filter((url) => url !== undefined),
name: 'Mainnet',
},
3: {
urls: [
process.env.REACT_APP_INFURA_KEY ? `https://ropsten.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}` : undefined,
process.env.REACT_APP_ALCHEMY_KEY
? `https://eth-ropsten.alchemyapi.io/v2/${process.env.REACT_APP_ALCHEMY_KEY}`
: undefined,
process.env.REACT_APP_POCKET_KEY
? `https://eth-ropsten.gateway.pokt.network/v1/lb/${process.env.REACT_APP_POCKET_KEY}`
: undefined,
].filter((url) => url !== undefined),
name: 'Ropsten',
},
};
and here's how I initialized the connector:
export const [NetworkConnector, NetworkHooks, NetworkStore] = initializeConnector(
(actions) => new Network(actions, RPCEndpoints, true, 1),
Object.keys(RPCEndpoints).map((chainId) => Number(chainId))
);
however when the first one fails (for instance when you provide a false KEY and it returns error 401), this error is thrown:
Could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.5.3)
and when this happens the activate() process fails (both isActivating and isActive are false). Is there a way to activate the same NetworkConnector with a different RPC endpoint?