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

@protocol-01/rpc-config

v0.1.2

Published

Shared RPC configuration for Protocol 01 — priority-based endpoint resolution, connection management with automatic fallback, URL sanitization, and explorer URL builders.

Readme

@protocol-01/rpc-config

Smart RPC connection manager for Solana with priority-based failover.

Install

npm install @protocol-01/rpc-config @solana/web3.js

Quick Start

import { RpcConnectionManager } from '@protocol-01/rpc-config';

const rpc = new RpcConnectionManager({ cluster: 'devnet' });
const connection = rpc.getConnection(); // ready to use

The connection automatically uses the best available endpoint. If one goes down, call switchEndpoint() or use checkHealthWithFailover() to cycle to the next one.

Features

  • Priority-based endpoint selection (QuickNode > Helius > Public RPC)
  • Health check with timeout and automatic failover
  • Explorer URL builders (Solana Explorer, Solscan)
  • Endpoint URL validation and API key sanitization for safe logging

Configuration

Basic (public RPC)

const rpc = new RpcConnectionManager({ cluster: 'mainnet-beta' });

With Helius

const rpc = new RpcConnectionManager({
  cluster: 'mainnet-beta',
  heliusApiKey: process.env.HELIUS_API_KEY,
});

With QuickNode (highest priority)

const rpc = new RpcConnectionManager({
  cluster: 'mainnet-beta',
  quicknodeEndpoint: 'https://your-endpoint.quiknode.pro/...',
  heliusApiKey: process.env.HELIUS_API_KEY, // fallback
});

Custom endpoints

import { RpcConnectionManager, type RpcEndpoint } from '@protocol-01/rpc-config';

const custom: RpcEndpoint = {
  http: 'https://my-rpc.example.com',
  ws: 'wss://my-rpc.example.com',
  provider: 'custom',
  priority: 0, // highest priority
};

const rpc = new RpcConnectionManager({
  cluster: 'mainnet-beta',
  customEndpoints: [custom],
});

Endpoint priority order

| Priority | Provider | Condition | |---|---|---| | 0 | QuickNode | quicknodeEndpoint provided | | 1 | Helius | heliusApiKey provided | | 2 | Solana public | Always included as fallback | | N | Custom | Whatever priority you set |

Health Checks and Failover

// Check current endpoint health (with 5s default timeout)
const { healthy, latencyMs } = await rpc.checkHealth();

// Check with custom timeout
const result = await rpc.checkHealth(3000);

// Auto-failover: tries each endpoint, returns first healthy connection
try {
  const connection = await rpc.checkHealthWithFailover();
} catch (err) {
  // All endpoints failed -- err.message lists what was tried
}

Handling RPC errors

try {
  await connection.getBalance(pubkey);
} catch (error) {
  const switched = rpc.handleError(error as Error);
  if (switched) {
    // Retry with new endpoint
    const newConnection = rpc.getConnection();
    await newConnection.getBalance(pubkey);
  }
}

The manager auto-switches on: 429 (rate limit), 502/503 (server down), fetch failures, ECONNREFUSED, ETIMEDOUT, socket hang up, and Blockhash not found.

Listening for endpoint switches

const rpc = new RpcConnectionManager({
  cluster: 'devnet',
  onEndpointSwitch: (from, to) => {
    console.log(`Switched from ${from.provider} to ${to.provider}`);
  },
});

Explorer URLs

import { getExplorerUrl, getSolscanUrl } from '@protocol-01/rpc-config';

const txSig = '5abc...';
getExplorerUrl(txSig, 'devnet', 'tx');
// => https://explorer.solana.com/tx/5abc...?cluster=devnet

getSolscanUrl(txSig, 'mainnet-beta', 'tx');
// => https://solscan.io/tx/5abc...

getExplorerUrl('7gWp...', 'devnet', 'address');
// => https://explorer.solana.com/address/7gWp...?cluster=devnet

URL Sanitization

import { sanitizeRpcUrl, validateRpcEndpoint } from '@protocol-01/rpc-config';

// Safe for logging -- masks API keys
sanitizeRpcUrl('https://mainnet.helius-rpc.com/?api-key=SECRET123');
// => https://mainnet.helius-rpc.com/?api-key=***

// Throws if not HTTPS (localhost is exempt)
validateRpcEndpoint('http://evil.com/rpc'); // Error!
validateRpcEndpoint('http://127.0.0.1:8899'); // OK

API Reference

Connection Management

| Export | Description | |---|---| | RpcConnectionManager | Main class -- manages connections with failover | | .getConnection() | Get the current Connection (lazy-created) | | .switchEndpoint() | Advance to next endpoint, return new Connection | | .resetConnection() | Drop cached connection (same endpoint) | | .getCurrentEndpoint() | Get metadata about the active endpoint | | .getCluster() | Get the configured cluster name | | .checkHealth(timeoutMs?) | Probe current endpoint (default 5s timeout) | | .checkHealthWithFailover(timeoutMs?) | Try all endpoints, return first healthy one | | .handleError(error) | Auto-switch on known RPC errors, returns true if switched |

Endpoints

| Export | Description | |---|---| | getEndpoints(cluster, options?) | Build a sorted list of RPC endpoints | | getDefaultRpcUrl(cluster) | Get the public RPC URL for a cluster |

Utilities

| Export | Description | |---|---| | sanitizeRpcUrl(url) | Redact API keys for safe logging | | validateRpcEndpoint(url) | Throw if URL is not HTTPS (localhost exempt) | | getExplorerUrl(value, cluster, type?) | Build Solana Explorer URL | | getSolscanUrl(value, cluster, type?) | Build Solscan URL |

Types

| Type | Description | |---|---| | SolanaCluster | 'mainnet-beta' \| 'devnet' \| 'testnet' \| 'localnet' | | RpcEndpoint | { http, ws, provider, priority } | | ConnectionConfig | Full config for RpcConnectionManager | | GetEndpointsOptions | Options for getEndpoints() |

License

MIT