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 theMinaConfig 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
Environment-Based Configuration
A common pattern for managing RPCs across environments:React / Next.js Configuration
For React applications, configure RPCs in your provider:- Next.js (App Router)
- Vite
Fallback Behavior
When a custom RPC fails, the SDK does not automatically fall back to public RPCs. This is by design to ensure:- Predictable behavior - Your app uses the RPCs you configured
- Security - Private transactions stay private
- Debugging - RPC issues are surfaced, not hidden
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.
