Overview
MoonKey exposes two key parameters for network configuration: a default chain and a list of supported chains. If you don’t configure these parameters, MoonKey will use its default configuration which supports popular networks out of the box.Default Chain
The default chain is the primary network that your application’s wallets will use. For embedded wallets:- When users authenticate or create a wallet, MoonKey initializes it on the default chain
- The embedded wallet will use the default chain for all operations unless explicitly switched to another supported chain
- When users connect, MoonKey will prompt them to switch to the default chain if their wallet supports it
- Users can decline the prompt and remain on their current network
- Users can manually switch their wallet’s network at any time (MoonKey cannot prevent this)
Some wallets have limited network support. Rainbow Wallet’s mobile app doesn’t support testnets, and Trust Wallet SWIFT only supports specific networks (BSC, Polygon, Avalanche C-Chain, Arbitrum, OP Mainnet, Base, OpBNB).
Supported Chains
The supported chains list defines which networks are permitted in your application. This acts as a guardrail to prevent accidental transactions on unintended networks. For embedded wallets:- Attempting to send transactions on unsupported chains will throw an error
- Attempting to switch to an unsupported chain will throw an error
- Programmatic network switches to unsupported chains will throw an error
- Users can still manually switch their wallet to any network (this cannot be prevented)
- If you set
supportedChainsbut notdefaultChain, embedded wallets default to the first entry in the supported chains list - External wallets won’t be prompted to switch networks on connection
- The default chain must be included in the supported chains list
Configuration
MoonKey embedded wallets support any EVM-compatible chain. Here’s how to configure them.Using viem-Supported Networks
Step 1: Install viem First, install theviem package which contains JSON representations of popular EVM networks:
viem/chains:
MoonKeyProvider configuration:
supportedChainscannot be an empty arraydefaultChainmust be included insupportedChains- The provider will throw an error if these rules are violated
Using Custom Networks
Step 1: Define your custom chain Use viem’sdefineChain method to create a chain configuration:
id— Chain IDname— Human-readable namenetwork— Network identifiernativeCurrency— Native token details (name, symbol, decimals)rpcUrls— RPC endpoints (HTTP and/or WebSocket)blockExplorers— Block explorer URL
MoonKeyProvider:
Custom RPC Providers
By default, MoonKey uses its own RPC providers for transactions. These are subject to rate limits suitable for development and moderate production usage. For production applications with significant traffic, we strongly recommend using your own RPC providers from services like Alchemy, Infura, QuickNode, or Blast. Benefits of custom RPC providers:- Control over rate limits and throughput
- Better monitoring and analytics
- Reduced latency with dedicated infrastructure
- SLA guarantees
Overriding RPC URLs
To use a custom RPC provider with MoonKey: Step 1: Import the helper functionMultiple chains with custom RPCs
Override multiple chains at once:Default Configuration
If you don’t specifydefaultChain or supportedChains, MoonKey defaults to supporting popular EVM networks:
Default Supported Networks
| Network | Chain ID | Testnet |
|---|---|---|
| Ethereum Mainnet | 1 | |
| Ethereum Sepolia | 11155111 | ✅ |
| Base | 8453 | |
| Base Sepolia | 84532 | ✅ |
| Polygon | 137 | |
| Polygon Amoy | 80002 | ✅ |
| Arbitrum One | 42161 | |
| Arbitrum Sepolia | 421614 | ✅ |
| Optimism | 10 | |
| Optimism Sepolia | 11155420 | ✅ |
| Avalanche C-Chain | 43114 | |
| Avalanche Fuji | 43113 | ✅ |
| BNB Smart Chain | 56 | |
| BNB Testnet | 97 | ✅ |
| Celo | 42220 | |
| Celo Alfajores | 44787 | ✅ |
| Linea | 59144 | |
| Linea Testnet | 59140 | ✅ |
| Zora | 7777777 | |
| Zora Sepolia | 999999999 | ✅ |
- Embedded wallets initialize on Ethereum mainnet (or the user’s last-used network)
- External wallets aren’t prompted to switch networks
- All networks in the table above are available for use
Switching Networks
Once configured, you can programmatically switch networks using MoonKey hooks.Switch embedded wallet network
Get current network
Common Configurations
Mainnet-only application
Layer 2 focused
Development with testnets
Multi-chain with custom RPC
Best Practices
Choose appropriate networks
- Mainnet for production — Use mainnet and established L2s for production deployments
- Testnets for development — Use Sepolia, Amoy, etc. during development to avoid real costs
- Limit network count — Only support networks your application actually uses
Use environment variables
Store RPC URLs and chain configurations in environment variables:Monitor RPC usage
When using custom RPC providers:- Set up monitoring and alerts for rate limits
- Track RPC call volumes and errors
- Have fallback providers configured
- Monitor response times and uptime
Test network switching
Always test network switching functionality:- Verify embedded wallets switch correctly
- Test external wallet prompts
- Handle user rejection of network switches
- Display clear network indicators in your UI
Troubleshooting
Chain not appearing in wallet
Problem: Users don’t see your configured chain in their wallet. Solutions:- Verify the chain is in
supportedChains - Check that chain ID and RPC URL are correct
- For custom chains, ensure all required fields are defined
- Some wallets require manual network addition
RPC rate limit errors
Problem: Transactions fail with rate limit errors. Solutions:- Use custom RPC providers (Alchemy, Infura, QuickNode)
- Implement RPC URL overrides
- Add fallback RPC endpoints
- Monitor your RPC usage and upgrade plans as needed
Network switch fails
Problem:switchChain throws an error or doesn’t work.
Solutions:
- Ensure target chain is in
supportedChains - For external wallets, check wallet supports the network
- Handle errors gracefully when users decline switches
- Verify RPC endpoints are accessible
Configuration errors on startup
Problem:MoonKeyProvider throws an error during initialization.
Solutions:
- Ensure
defaultChainis included insupportedChains - Don’t pass empty array to
supportedChains - Verify chain objects are properly formatted
- Check for typos in chain imports