ar.io SDKAdvanced
Circuit Breaker
The SDK ships an [opossum]-backed circuit breaker that wraps the RPC transport. When the primary endpoint starts failing (429 rate-limits, 5xx errors, network timeouts) the circuit opens and subsequent calls route transparently to a fallback RPC until the primary recovers.
import { ARIO, createCircuitBreakerRpc } from '@ar.io/sdk';
const rpc = createCircuitBreakerRpc({
primaryUrl: 'https://my-premium-rpc.example.com',
fallbackUrl: 'https://api.mainnet-beta.solana.com',
});
const ario = ARIO.init({ rpc });Use defaultFallbackUrl() to auto-pick mainnet or devnet based on the
primary URL:
import {
createCircuitBreakerRpc,
defaultFallbackUrl,
} from '@ar.io/sdk';
const primaryUrl = 'https://my-premium-rpc.example.com';
const rpc = createCircuitBreakerRpc({
primaryUrl,
fallbackUrl: defaultFallbackUrl(primaryUrl), // → mainnet public RPC
});Tuning knobs (all optional):
| Option | Default | Description |
|---|---|---|
timeout | 10000 | ms before a single request is timed out (false to disable) |
errorThresholdPercentage | 50 | error % at which to open the circuit |
resetTimeout | 30000 | ms to wait before probing the primary again (half-open) |
volumeThreshold | 5 | minimum requests in the rolling window before the circuit can trip |
How is this guide?