npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ethers-dynamic-provider

v1.0.4

Published

ethers.js provider that supports multiple RPC endpoints with various routing strategies

Readme

ethers-dynamic-provider

Drop-in replacement for ethers.js JsonRpcProvider with built-in support for balancing between multiple RPC endpoints.

Installation

npm install ethers-dynamic-provider
# or
yarn add ethers-dynamic-provider
# or
pnpm add ethers-dynamic-provider

Usage

DynamicProvider is a powerful replacement for JsonRpcProvider with the same API. This means that you can simply replace the initialization of the provider and all the rest of the code will work as before, but with added benefits such as:

  • Automatic failover between multiple RPC endpoints using different strategies.
  • Built-in support for multicall functionality.
import { DynamicProvider, FallbackStrategy } from 'ethers-dynamic-provider'

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"], // add another RPC as fallback
  {
    strategy: new FallbackStrategy(),
  }
)

// Use like a normal ethers.js provider
const block = await provider.getBlockNumber()

Built-in multicall

Multicall functionality is provided by the ethers-multicall-provider and can be enabled if needed.

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new RandomStrategy(),
    multicall: true,
    // or with addition settings
    multicall: {
      cache: true,
      maxDataLength: 100_000,
    },
  }
);

Jailing

When the RPC returns an error it is put into "jail" and can no longer be selected for some time. By default it is 10 seconds, but you can adjust this time (or disable it by setting 0)

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new RandomStrategy(),
    jailDuration: 5_000, // 5 seconds
  }
);

Different strategies and RPCs for read and write requests

You can use different strategies or RPCs for read and write operations. Read operations are used when reading data from contracts, while write operations are used when sending transactions.

For example, I want to send transactions always to the same RPC:

import {
  DynamicProvider,
  RandomStrategy,
  FallbackStrategy,
} from "ethers-dynamic-provider";

const provider = new DynamicProvider(
  {
    read: ["https://rpc1.example.com", "https://rpc2.example.com"],
    write: ["https://rpc3.example.com"],
  },
  {
    strategy: {
      read: new RandomStrategy(),
      write: new FallbackStrategy(),
    },
  }
);

Available Strategies

FallbackStrategy

Uses a primary RPC endpoint and only switches to the next one when the current RPC fails

import { DynamicProvider, FallbackStrategy } from "ethers-dynamic-provider";

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new FallbackStrategy(),
  }
);

RandomStrategy

Randomly selects an RPC endpoint from the available list

import { DynamicProvider, RandomStrategy } from "ethers-dynamic-provider";

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new RandomStrategy(),
  }
);

SequentialStrategy

Uses RPC endpoints in sequence, switching to the next one when number of requests to current RPC reaches requestsPerRpc limit

import { DynamicProvider, SequentialStrategy } from "ethers-dynamic-provider";

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new SequentialStrategy({
      requestsPerRpc: 10, // default 5
    }),
  }
);

HighestBlockStrategy

Selects the RPC endpoint with the highest block number. The block number is synchronized at the first request, and then every syncInterval milliseconds

import { DynamicProvider, HighestBlockStrategy } from "ethers-dynamic-provider";

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new HighestBlockStrategy({
      syncInterval: 5_000, // default 10_000
    }),
  }
);

FastestStrategy

Sends requests to all RPCs simultaneously and returns the first successful response

import { DynamicProvider, FastestStrategy } from "ethers-dynamic-provider";

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new FastestStrategy(),
  }
);

DynamicStrategy

Analyzes response time of each RPC and selects the fastest one based on average response time of the last historyDepth requests

import { DynamicProvider, DynamicStrategy } from "ethers-dynamic-provider";

const provider = new DynamicProvider(
  ["https://rpc1.example.com", "https://rpc2.example.com"],
  {
    strategy: new DynamicStrategy({
      historyDepth: 10, // default 5
    }),
  }
);