This guide explains how to use Chainstack RPC endpoints with MetaMask. It covers obtaining an endpoint, adding a custom network in MetaMask, testing the connection, and resolving common errors. The steps apply to Ethereum and other EVM-compatible chains supported by Chainstack.
Why Use Chainstack RPC with MetaMask?
MetaMask comes with default RPC providers, but these can be rate-limited or congested during peak usage. Switching to a dedicated RPC endpoint like Chainstack can improve reliability and performance for your wallet interactions.
Chainstack provides managed blockchain nodes with RPC endpoints for Ethereum and other EVM networks. Using a Chainstack endpoint in MetaMask gives you a direct connection to the network, which can reduce latency and provide more consistent access to on-chain data.
- Dedicated endpoints may offer better uptime than public RPCs.
- You control the API key and can rotate it if needed.
- Supports multiple EVM chains, allowing you to add several custom networks in MetaMask.
Obtaining a Chainstack RPC Endpoint
To use Chainstack with MetaMask, you first need an RPC endpoint. If you don't have a Chainstack account, you can sign up for one. After logging in, create a project and deploy a node for the network you want to use (e.g., Ethereum Mainnet).
Once the node is running, you'll find the RPC endpoint URL in the node's details. It typically looks like https://your-node-id.chainstack.com/your-api-key. Keep this URL secure and do not share it publicly.
- Create a Chainstack account and project.
- Deploy a node for your desired network.
- Copy the HTTPS RPC endpoint from the node dashboard.
https://your-node-id.chainstack.com/your-api-keyAdding a Custom Network in MetaMask
Open MetaMask and click the network selector at the top. Select 'Add network' and then 'Add a network manually'. Fill in the network details using the Chainstack endpoint.
For Ethereum Mainnet, use the following values: Network Name: Chainstack Ethereum; New RPC URL: your Chainstack endpoint; Chain ID: 1; Currency Symbol: ETH; Block Explorer URL: https://etherscan.io (optional).
If you are using a testnet or another EVM chain, replace the Chain ID and currency symbol accordingly. You can find the correct Chain ID from the network's documentation.
- Network Name: Any name you prefer (e.g., Chainstack Ethereum).
- New RPC URL: Your Chainstack HTTPS endpoint.
- Chain ID: The numeric ID of the network (1 for Ethereum Mainnet).
- Currency Symbol: ETH (or the native token symbol).
- Block Explorer URL: Optional, but useful for viewing transactions.
Testing the Connection
After saving the network, MetaMask will switch to it. You can verify the connection by checking your account balance or sending a small test transaction. If the balance displays correctly and transactions go through, the RPC endpoint is working.
You can also use the MetaMask 'Settings > Networks' menu to view the current RPC URL and ensure it matches your Chainstack endpoint.
- Check that your ETH balance appears.
- Try a small transaction to confirm functionality.
- Monitor the node's status in the Chainstack dashboard for any issues.
Troubleshooting Common Issues
If MetaMask shows an error like 'Could not fetch chain ID' or 'Network request failed', double-check the RPC URL and Chain ID. Ensure the endpoint is correct and the node is running.
If you receive rate-limiting errors, verify your Chainstack plan's request limits. Upgrading your plan or optimizing your dapp's request frequency may help.
For persistent issues, consult Chainstack's documentation or support. MetaMask's logs (via Settings > Advanced > State Logs) can provide additional details.
- Verify the RPC URL is copied correctly, including the API key.
- Ensure the Chain ID matches the network.
- Check that your Chainstack node is active and not paused.
- Review rate limits if you encounter 429 errors.
Security and Best Practices
Treat your Chainstack API key like a password. Avoid exposing it in client-side code or public repositories. If you suspect it has been compromised, rotate the key in the Chainstack dashboard.
For production dapps, consider using environment variables to store the endpoint and restrict access by domain or IP where possible. Chainstack offers security features like API key restrictions that can help.
- Never commit API keys to version control.
- Use environment variables for endpoint configuration.
- Rotate keys periodically and monitor usage.