This guide explains how to use Alchemy RPC endpoints with MetaMask. It covers obtaining an Alchemy RPC URL, adding a custom network in MetaMask, and troubleshooting common connection issues. The focus is on the practical steps for configuring MetaMask to send requests through Alchemy.
What Is Alchemy RPC and Why Use It with MetaMask?
Alchemy is a blockchain infrastructure provider that offers RPC (Remote Procedure Call) endpoints for various networks. MetaMask is a popular crypto wallet that can connect to Ethereum and other EVM-compatible networks via custom RPC URLs. Using Alchemy RPC with MetaMask allows you to route your wallet's requests through Alchemy's infrastructure, which can be useful for developers testing dApps or users who prefer a specific provider.
MetaMask comes with default RPC endpoints for common networks, but you can replace them with a custom RPC URL from Alchemy. This is often done to access enhanced reliability, developer tools, or specific network support that Alchemy provides.
- Alchemy provides RPC endpoints for Ethereum, Polygon, Arbitrum, Optimism, and other networks.
- MetaMask supports custom RPC URLs for EVM networks.
- Using Alchemy RPC can help developers monitor requests via Alchemy's dashboard.
How to Get an Alchemy RPC URL for MetaMask
To use Alchemy with MetaMask, you first need an Alchemy account and an app created in the Alchemy dashboard. The dashboard provides an HTTPS endpoint that you can copy and paste into MetaMask. The endpoint format typically looks like: https://<network>.g.alchemy.com/v2/<your-api-key>.
After signing up and creating an app, select the network you want (e.g., Ethereum Mainnet, Polygon Mainnet) and copy the corresponding HTTPS URL. Keep your API key secure and avoid sharing it publicly.
- Create an Alchemy account and log in to the dashboard.
- Create a new app and select the desired network.
- Copy the HTTPS endpoint from the app's details page.
https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEYAdding Alchemy RPC to MetaMask: Step-by-Step
Once you have your Alchemy RPC URL, you can add it to MetaMask as a custom network. Open MetaMask, click the network selector, and choose 'Add network' or 'Custom RPC'. Fill in the network details, including the network name, the Alchemy RPC URL, chain ID, and currency symbol. For example, for Ethereum Mainnet, the chain ID is 1 and the symbol is ETH.
After saving, switch to the new network. MetaMask will now send requests to Alchemy instead of the default RPC. You can verify the connection by checking the network name and ensuring balances and transactions load correctly.
- Open MetaMask and go to Settings > Networks > Add network.
- Enter a name (e.g., 'Ethereum via Alchemy').
- Paste the Alchemy RPC URL in the 'New RPC URL' field.
- Set the chain ID (1 for Ethereum Mainnet, 137 for Polygon, etc.).
- Enter the currency symbol (ETH, MATIC, etc.) and block explorer URL (optional).
- Save and switch to the new network.
Network name: Ethereum via Alchemy
New RPC URL: https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
Chain ID: 1
Currency symbol: ETH
Block explorer URL: https://etherscan.ioCommon Networks and Alchemy RPC Endpoints
Alchemy supports multiple networks, each with its own endpoint pattern. Below are examples of endpoint formats for popular networks. Replace YOUR_API_KEY with your actual Alchemy API key. Note that Alchemy may update endpoint URLs, so always refer to your Alchemy dashboard for the latest URLs.
- Ethereum Mainnet: https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
- Polygon Mainnet: https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY
- Arbitrum Mainnet: https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY
- Optimism Mainnet: https://opt-mainnet.g.alchemy.com/v2/YOUR_API_KEY
https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEYTroubleshooting Alchemy RPC with MetaMask
If MetaMask fails to connect using an Alchemy RPC URL, check the following: ensure the URL is correct and includes your API key; verify the chain ID matches the network; confirm your Alchemy app is active and not rate-limited. Common errors include 'Could not fetch chain ID' or 'Network request failed', which often indicate an incorrect URL or network mismatch.
Also, ensure that your API key has permissions for the network you are trying to access. If you are using a free tier, be aware of request limits that may cause intermittent failures. For persistent issues, consult Alchemy's documentation or support.
- Double-check the RPC URL for typos or missing API key.
- Verify the chain ID is correct for the network.
- Check Alchemy dashboard for app status and usage limits.
- Try switching back to the default MetaMask RPC to isolate the issue.
Security and Best Practices
When using a custom RPC like Alchemy with MetaMask, keep your API key confidential. Exposing your key can lead to unauthorized use and potential rate-limiting or charges. Avoid committing keys to public repositories. Additionally, consider using environment variables or secret managers in development environments.
MetaMask stores network configurations locally, so anyone with access to your device could view the RPC URL. If you share your device, be mindful of this. For production dApps, use Alchemy's API key restrictions (e.g., allowlists) to limit exposure.
- Never share your Alchemy API key publicly.
- Use separate API keys for different applications.
- Enable allowlists or restrictions in Alchemy dashboard if available.
- Regularly rotate keys if you suspect compromise.