ethers-fallback-provider

Package providing a fallback provider based on ethers
package, adding more resilience.
The provider fallbacks on multiple providers in case of failure, and returns the first successful result.
It throws an error if all providers failed.
The providers are called in the order they are passed to the constructor.
Contrary to the FallbackProvider
provided by ethers
, this one does not use all providers at the same time, but only one at a time.
The purpose is more to have resilience if one provider fails, rather than having a resilience on the result.
Installation
npm install @morpho-labs/ethers-fallback-provider
or
yarn add @morpho-labs/ethers-fallback-provider
Usage
import FallbackProvider from '@morpho-labs/ethers-fallback-provider';
import {
InfuraProvider,
AlchemyProvider,
getDefaultProvider
} from "@ethersproject/providers";
const timeout = 1000;
const provider = new FallbackProvider([
{
provider: new InfuraProvider('mainnet', 'your-api-key'),
retries: 3,
timeout,
retryDelay: 1000
},
new AlchemyProvider('mainnet', 'your-api-key'),
getDefaultProvider('mainnet')
]);
const blockNumber = await provider.getBlockNumber();