I am trying to connect Metamask to ganache by creating a custom RPC with the following details:


Chain Id: 5777

But I keep getting the error message The endpoint returned a different chain ID: 0x539

  • still not sure why network ID and chain ID are different for ganache most of the time they are the same - see my answer below
    – James Daly
    Commented Nov 22, 2020 at 21:28

9 Answers 9


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.

  • How do you do this?
    – cilphex
    Commented Dec 22, 2022 at 0:40

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:

  • Upgrade ganache-cli to v.6.11.0 or above, then start it with the --chainId flag, for example: ganache-cli --deterministic -i 5777 --chainId 5777
  • Then setup your custom RPC in Metamask with the same chainId.

You may be able to simply upgrade your Ganache GUI version and achieve the same thing.

  • adding --deterministic -i xxxx did it for me, with only --chainId xxxx I always got a different chainId which is randomly created Commented Mar 17, 2022 at 17:11

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.

Changing Ganache NETWORK ID


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.

  • 1
    Thanks for answering! Could you clarify what you mean by "locking Metamask"? Commented Dec 7, 2020 at 8:04

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


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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.