Skip to main content

Custom RPC URLs

The Mina SDK supports custom RPC URL configuration for each chain. This allows you to use your own RPC endpoints for improved reliability, higher rate limits, and private transactions.

Why Use Custom RPCs

Reliability

Public RPCs can be unreliable during high traffic. Premium RPCs offer better uptime guarantees.

Rate Limits

Public RPCs have strict rate limits. Custom RPCs provide higher throughput for production applications.

Privacy

Private RPCs prevent transaction frontrunning and provide better MEV protection.

Speed

Premium RPCs often have lower latency and faster response times.

Basic Configuration

Pass custom RPC URLs in the MinaConfig when creating the client:
The rpcUrls object maps chain IDs to RPC endpoint URLs. You only need to specify RPCs for chains you plan to use.

Provider Examples

Alchemy

Infura

QuickNode

Ankr

Per-Chain Configuration

You can configure RPCs for specific chains while leaving others to use defaults:

Common Chain IDs

Do not expose API keys in client-side code. For browser applications, use environment variables or a backend proxy to hide your RPC API keys.

Environment-Based Configuration

A common pattern for managing RPCs across environments:

React / Next.js Configuration

For React applications, configure RPCs in your provider:

Fallback Behavior

When a custom RPC fails, the SDK does not automatically fall back to public RPCs. This is by design to ensure:
  1. Predictable behavior - Your app uses the RPCs you configured
  2. Security - Private transactions stay private
  3. Debugging - RPC issues are surfaced, not hidden
To implement your own fallback logic:

Best Practices

Use Environment Variables

Never hardcode API keys. Use environment variables for all sensitive configuration.

Configure Key Chains

At minimum, configure RPCs for chains you expect high traffic on (usually Ethereum and your primary L2s).

Monitor Usage

Set up monitoring on your RPC provider dashboard to track usage and avoid hitting limits.

Test Both Environments

Use separate API keys for development and production to isolate usage and billing.

Complete Configuration Example