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

@tetherto/wdk-provider-failover

v1.0.0-beta.2

Published

A simple package to initialize WDK wallet instances with failover capabilities.

Readme

@tetherto/wdk-provider-failover

A resilient wrapper for WDK wallet instances that provides automatic failover across multiple provider configurations with configurable retry logic.

Features

  • Automatic failover - Cascades through multiple provider configurations when failures occur
  • Configurable retries - Retry failed operations with exponential backoff and jitter
  • Lazy instantiation - Wallet instances are created only when needed
  • Proxy-based - Transparent wrapper that preserves the original wallet API
  • Lifecycle management - Proper cleanup of resources via dispose()

Installation

npm install @tetherto/wdk-provider-failover

Usage

Basic Example

import { createFallbackWallet } from '@tetherto/wdk-provider-failover'
import { WalletAccountReadOnlyEvm } from '@tetherto/wdk-wallet-evm'

const wallet = createFallbackWallet(
  WalletAccountReadOnlyEvm,
  ['0x742d35Cc6634C0532925a3b844Bc9e7595f...'], // constructor args
  {
    primary: { provider: 'https://mainnet.infura.io/v3/YOUR_KEY' },
    fallbacks: [
      { provider: 'https://eth.llamarpc.com' },
      { provider: 'https://ethereum.publicnode.com' }
    ]
  }
)

// Use the wallet as normal - failover is automatic
const balance = await wallet.getBalance()

// Clean up when done
await wallet.dispose()

With Custom Options

const wallet = createFallbackWallet(
  WalletAccountReadOnlyEvm,
  [address],
  {
    primary: { provider: primaryRpcUrl },
    fallbacks: [
      { provider: fallbackRpcUrl1 },
      { provider: fallbackRpcUrl2 }
    ],
    fallbackOptions: {
      timeout: 5000,              // 5 second timeout per call
      maxRetries: 3,              // Retry current provider 3 times before switching
      retryDelay: 1000,           // Base delay between retries (ms)
      exponentialBackoff: true,   // Double delay on each retry
      jitter: true,               // Add randomness to prevent thundering herd
      fallbackMethods: ['getBalance', 'getTransactions'], // Only wrap specific methods
      logger: customLogger,       // Custom logging function
      onFallback: (index, config) => {
        console.log(`Switching to provider ${index}`)
      },
      onConfigSwitch: (index, config) => {
        console.log(`Successfully using provider ${index}`)
      }
    }
  }
)

API

createFallbackWallet(WalletClass, constructorArgs, config)

Factory function that creates a failover-wrapped wallet instance.

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | WalletClass | class | The wallet class to instantiate | | constructorArgs | array | Arguments passed to the wallet constructor (before config) | | config | object | Configuration object (see below) |

Config Object:

| Property | Type | Description | |----------|------|-------------| | primary | object | Primary provider configuration | | fallbacks | array | Array of fallback provider configurations | | fallbackOptions | object | Options for failover behavior (see below) |

Fallback Options:

| Option | Type | Default | Description | |--------|------|---------|-------------| | timeout | number | 10000 | Timeout per method call (ms) | | maxRetries | number | 3 | Retries per provider before switching | | retryDelay | number | 1000 | Base delay between retries (ms) | | exponentialBackoff | boolean | true | Double delay on each retry | | jitter | boolean | true | Add ±15% randomness to delays | | fallbackMethods | string[] | [] | Methods to wrap (empty = all methods) | | logger | function | console | Custom logger function | | onFallback | function | - | Called when switching to a fallback provider | | onConfigSwitch | function | - | Called on successful operation after retries |

Proxy Methods

The returned proxy exposes additional utility methods:

| Method | Returns | Description | |--------|---------|-------------| | dispose() | Promise<void> | Disposes all wallet instances | | getActiveIndex() | number | Current active provider index | | getActiveConfig() | object | Current active provider config | | getInstancesCount() | number | Total number of configured providers | | switchTo(index) | number | Manually switch to a specific provider | | getInstanceUnsafe() | object | Get the current wallet instance directly |

How It Works

  1. When a method is called on the proxy, it attempts the operation on the current provider
  2. If the call fails or times out, it retries up to maxRetries times with backoff
  3. After exhausting retries, it switches to the next provider in the cascade
  4. This continues until success or all providers have been exhausted
  5. On success, callbacks are invoked to notify of the active configuration
┌─────────────┐     fail      ┌─────────────┐     fail      ┌─────────────┐
│   Primary   │──── retry ───▶│  Fallback 1 │──── retry ───▶│  Fallback 2 │
│  Provider   │   (3 times)   │   Provider  │   (3 times)   │   Provider  │
└─────────────┘               └─────────────┘               └─────────────┘

Custom Logger

The logger function receives structured log data:

const logger = (level, message, meta) => {
  // level: 'debug' | 'info' | 'warn' | 'error'
  // message: string description
  // meta: object with additional context
  console.log(`[${level}] ${message}`, meta)
}

License

Apache-2.0