New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@tetherto/wdk-provider-failover

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tetherto/wdk-provider-failover

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

latest
npmnpm
Version
1.0.0-beta.2
Version published
Maintainers
3
Created
Source

@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:

ParameterTypeDescription
WalletClassclassThe wallet class to instantiate
constructorArgsarrayArguments passed to the wallet constructor (before config)
configobjectConfiguration object (see below)

Config Object:

PropertyTypeDescription
primaryobjectPrimary provider configuration
fallbacksarrayArray of fallback provider configurations
fallbackOptionsobjectOptions for failover behavior (see below)

Fallback Options:

OptionTypeDefaultDescription
timeoutnumber10000Timeout per method call (ms)
maxRetriesnumber3Retries per provider before switching
retryDelaynumber1000Base delay between retries (ms)
exponentialBackoffbooleantrueDouble delay on each retry
jitterbooleantrueAdd ±15% randomness to delays
fallbackMethodsstring[][]Methods to wrap (empty = all methods)
loggerfunctionconsoleCustom logger function
onFallbackfunction-Called when switching to a fallback provider
onConfigSwitchfunction-Called on successful operation after retries

Proxy Methods

The returned proxy exposes additional utility methods:

MethodReturnsDescription
dispose()Promise<void>Disposes all wallet instances
getActiveIndex()numberCurrent active provider index
getActiveConfig()objectCurrent active provider config
getInstancesCount()numberTotal number of configured providers
switchTo(index)numberManually switch to a specific provider
getInstanceUnsafe()objectGet the current wallet instance directly

How It Works

  • When a method is called on the proxy, it attempts the operation on the current provider
  • If the call fails or times out, it retries up to maxRetries times with backoff
  • After exhausting retries, it switches to the next provider in the cascade
  • This continues until success or all providers have been exhausted
  • 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

FAQs

Package last updated on 26 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts