Metamk configuration error: add hardhat as a network
When configuring the local blockchain network for use with MetamSk in Hardhat, there are several common errors that can occur. One of these problems implies incorrect RPC URL. In this article, we will go through what the error is causing and we will provide step -by -step solutions to solve it.
The error message:
The error message is generally seen:
NEW RPC URL:
Chainid: 31337
He could not obtain the identification of the chain. Is your RPC URL correct?
Understand the error
The error is caused by a misunderstanding of how Metamk resolves the URLs of RPC. The http: // 127.0.0.1 indicates that the RPC server is running in the local machine, which is fine for proof purposes. However, when using hardhat to implement and interact with the network, you must specify the correct RPC URL.
The problem here is probably due to one of two reasons:
* Incorrect chain ID : The error message suggests that there is a problem with obtaining the Metamask chain ID. This is unlikely, since it is a standard parameter required for RPC connections.
* The RPC server is not executed

: In some cases, the RPC server may not be executed or accessible in the specified URL. This could be due to several reasons, such as network problems, permission errors or configuration errors.
Solutions step by step:
To solve this problem, follow these steps:
1. Verify that the RPC server is running
Make sure your Metamask instance is configured to execute an RPC server in http: //127.0.0.1: 8545/. You can verify this by reviewing its MetamSk configuration in
Red >
URL RPC
.
If you are using a custom RPC URL, make sure it is correct and coincides with the one provided in the error message.
2. Verify the problems of the network
Try to connect to the local blockchain network using http: //127.0.1: 8545/. You can do this by copying the RPC URL from its Metamask instance:
Wss: //127.0.0.1: 8545/
If you still face problems, try to restart the RPC server or verify any network connectivity problem.
3. Verify the identification of the chain
Reflect that the chain ID is correct in its hardhat configuration file (usually hardhat.config.js o’packet.json). Make sure it matches the value provided in the error message (31337).
If you are not still sure of the chain ID, consider using a different RPC UR or verify the Metamask configuration again.
4. Update the hardhat configuration
If none of the previous steps solve the problem, try to update your hardhat configuration file to use the right RPC URL and the chain ID:
JavaScript
const {hardhatconfig} = require ('./ hardhat.config');
module.exports = hardhatconfig;
`
Following these steps, you should be able to solve the error « Add Hardhat as a network » in its Metamask configuration.