I am trying to connect Metamask to ganache by creating a custom RPC with the following details:
New RPC URL: HTTP://127.0.0.1:7545
Chain Id: 5777
But I keep getting the error message The endpoint returned a different chain ID: 0x539
I am trying to connect Metamask to ganache by creating a custom RPC with the following details:
New RPC URL: HTTP://127.0.0.1:7545
Chain Id: 5777
But I keep getting the error message The endpoint returned a different chain ID: 0x539
You either need to update your custom MetaMask Network to match the default chainId returned by Ganache (which is 1337) or, if you are using ganache-cli use a command like ganache-cli --port 7545 --chainId 5777 to change the chainId to 5777.
If you are using Ganache GUI you can't change the chainId, so you'll need to change it in MetaMask instead.
By Default ganache Chain ID: 1337 & Network ID: [veriable]
so, chenge your Network ID to same as Chain ID. for that Click on the settings icon at the top right of your Ganache Gui, then click on the server menu, change the NETWORK ID to 1337, and then click the save and restart button at the top right.
You appear to be using Ganache GUI, so this may not directly help you, but I can at least provide an explanation.
With Metamask 8.1.3 and above, local Ganache-cli blockchains began breaking due to a mismatching ChainId.
Fixing with the CLI is a matter of:
You may be able to simply upgrade your Ganache GUI version and achieve the same thing.
--deterministic -i xxxx did it for me, with only --chainId xxxx I always got a different chainId which is randomly created
– Irzhy Ranaivoarivony
Mar 17 '22 at 17:11
I had a similiar problem. In truffel.js the networkId was set to 1337. In the Ganache GUI, too. But when I return the the chainId with the contract function
function getChainId() public view returns (uint256 chainId) {
assembly {
chainId := chainid()
}
}
then i got 1 for the chainId. I know that the networkId is not the chainId. But theres is no way to configure the chainId when using the Ganache GUI.
I could not solve the problem but it works with using the trufflesuite / ganache (https://github.com/trufflesuite/ganache) instead. When I start ganache with
ganache --chain.chainId 1337 --chain.networkId 1337
then I get 1337 as chainId with the function described above.
The Ganache started on the command line works as good as the Ganache GUI but it is more flexible, because there are much more possibilities to configure Ganache when starting it up.
Try locking the account and when you are asked to sign in again use the option import wallet using mnemonic or seed phrase copy that from ganache and should be good to go
I was having the same error and locking the metamask and using Ganache mnemonic worked for me.
According to README.md of https://github.com/trufflesuite/ganache-cli, Ganache's core is having a legacy issue:
--chainId: Specify the Chain ID ganache-cli will use for eth_chainId RPC and the CHAINID opcode. For legacy reasons, the default is currently 1337 for eth_chainId RPC and 1 for the CHAINID opcode. Setting this flag will align the chainId values. This will be fixed in the next major version of ganache-cli and ganache-core!
But the detected 1337 chain id should be the same chain whose networkId is 5777
As workaround i've fixed it by changing the Server Port to 8545 and Chain ID to 1337 in Ganache GUI and saved/restart, i also needed to update truffle-config.js with the new info , now MetaMask connects
I thought I had a phantom ganache-cli process still running as that's how is looked, but it turns out it's just MetaMask/Ganache weirdness. I gave up trying to change the settings in MetaMask and ended up changing the Ganache GUI to 8545 & 1337. I would have just made this a comment on Joyal's post but I'm too noob to comment