Skip to content

bastiencodes/registry

Repository files navigation

Blockchain Provider Registry

A comprehensive registry of blockchain providers and networks with programmatic access to check provider-chain compatibility and endpoint construction.

Features

  • Provider Registry: Comprehensive list of blockchain providers (Infura, Alchemy, QuickNode, etc.)
  • Network Support: Extensive network coverage including Ethereum, Polygon, Arbitrum, and more
  • Type Safety: Full TypeScript support with literal types for better IDE suggestions
  • Runtime Validation: Valibot schemas for runtime JSON validation
  • Endpoint Construction: Automatic endpoint URL generation with API key substitution
  • Provider Compatibility: Check which providers support specific networks
  • Testing Infrastructure: Built-in endpoint testing with performance metrics

Installation

npm install @bastiencodes/registry

Quick Start

import { Registry } from "@bastiencodes/registry";

// Use the default registry instance
const registry = Registry.default;

// Get all supported networks
const networks = registry.getNetworks();

// Get all providers
const providers = registry.getProviders();

// Check if a provider supports a specific network
const isSupported = registry.isNetworkSupported("ethereum", "infura");

// Get endpoint for a provider-network combination
const endpoint = registry.getEndpoint("ethereum", "infura", "YOUR_API_KEY");

Usage Examples

Basic Usage

import { Registry } from "@bastiencodes/registry";

const registry = Registry.default;

// Get all Ethereum networks
const ethereumNetworks = registry.getNetworksByChain("ethereum");

// Get all providers that support Polygon
const polygonProviders = registry.getProvidersByNetwork("polygon");

// Construct endpoint URL
const endpoint = registry.getEndpoint("arbitrum", "alchemy", "your-api-key");
// Returns: https://arb-mainnet.g.alchemy.com/v2/your-api-key

Custom Registry Instance

import { Registry } from "@bastiencodes/registry";
import networks from "@bastiencodes/registry/networks.json";
import providers from "@bastiencodes/registry/providers.json";

// Create custom registry with your own networks and providers
const customRegistry = new Registry({
  networks,
  providers,
});

Runtime Validation

import {
  Registry,
  networkSchema,
  providerSchema,
} from "@bastiencodes/registry";

// Validate networks data
const networksResult = networkSchema.safeParse(networksData);
if (!networksResult.success) {
  console.error("Invalid networks data:", networksResult.error);
}

// Validate provider data
const providerResult = providerSchema.safeParse(providerData);
if (!providerResult.success) {
  console.error("Invalid provider data:", providerResult.error);
}

API Reference

Registry Class

Constructor

new Registry({ networks, providers });

Methods

  • getNetworks(): Get all networks
  • getProviders(): Get all providers
  • getNetwork(id): Get a specific network by ID
  • getProvider(id): Get a specific provider by ID
  • isNetworkSupported(networkId, providerId): Check if provider supports network
  • getEndpoint(networkId, providerId, apiKey): Get endpoint URL
  • getNetworksByChain(chainId): Get all networks for a chain
  • getProvidersByNetwork(networkId): Get all providers supporting a network

Types

  • NetworkId: Literal type for network identifiers
  • ProviderId: Literal type for provider identifiers
  • Network: Network configuration interface
  • Provider: Provider configuration interface
  • EndpointConfig: Endpoint configuration interface

Testing

The package includes a comprehensive testing script to verify endpoint connectivity:

# Run endpoint tests (requires .env file with API keys)
bun run test:endpoints

# Or run directly
bun run tests/test-endpoints.ts

Create a .env file based on env.template with your API keys:

# Required API keys for testing
INFURA_API_KEY=your_infura_key
ALCHEMY_API_KEY=your_alchemy_key
QUICKNODE_API_KEY=your_quicknode_key
THIRDWEB_API_KEY=your_thirdweb_key
BLAST_API_KEY=your_blast_key
DRPC_API_KEY=your_drpc_key
TENDERLY_API_KEY=your_tenderly_key

Supported Providers

  • Infura: Ethereum, Polygon, Arbitrum, Optimism, Base, and more
  • Alchemy: Ethereum, Polygon, Arbitrum, Optimism, Base, and more
  • QuickNode: Ethereum, Polygon, Arbitrum, Optimism, Base, Bitcoin, Solana
  • ThirdWeb: Ethereum, Polygon, Arbitrum, Optimism, Base, Bitcoin, Solana
  • Blast: Ethereum, Polygon, Arbitrum, Optimism, Base
  • dRPC: Ethereum, Polygon, Arbitrum, Optimism, Base, Bitcoin, Solana
  • Tenderly: Ethereum, Polygon, Arbitrum, Optimism, Base, Bitcoin, Solana

Supported Networks

The registry includes 50+ networks across multiple chains:

  • Ethereum: Mainnet, Goerli, Sepolia
  • Polygon: Mainnet, Mumbai
  • Arbitrum: One, Nova, Sepolia
  • Optimism: Mainnet, Sepolia
  • Base: Mainnet, Sepolia
  • BSC: Mainnet, Testnet
  • Avalanche: C-Chain, Fuji
  • Fantom: Opera, Testnet
  • Celo: Mainnet, Alfajores
  • Gnosis: Mainnet, Chiado
  • And many more...

Development

# Install dependencies
bun install

# Build the package
bun run build

# Run tests
bun run test

# Run endpoint tests
bun run test:endpoints

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published