Describe the bug
MM uses 2710 as chain id, instead of 31337 when connecting to Hardhat Network on localhost 8545. This makes transactions fail because Hardhat Network implements EIP155.
Steps to reproduce (REQUIRED)
Follow the steps here and try to make a tx from the frontend: https://github.com/nomiclabs/hardhat-hackathon-boilerplate
Expected behavior
The transaction you made in the frontend should succeed.
Screenshots


Browser details (please complete the following information):
(note that this was reported from multiple users with different configurations)
Additional context (Error Messages, etc.)
It may be a duplicate of https://github.com/MetaMask/metamask-extension/issues/9683, but note that Hardhat Network supports both net_version and eth_chainId. I don't see any eth_chainId being made though.
I currently have this issues if you need help reproducing this.
@rekmarks would you mind confirming this one?
@alcuadrado @jamespfarrell can you go to Settings > Network > Localhost 8545 and update the chain ID manually?
Note that if you enter a decimal value it'll be displayed as hex, but the value will be saved correctly.
@rekmarks Yes, setting 31337 as the chain id and then resetting the account makes the transaction work.
This might also be of help: if I uninstall and re-install MetaMask, the default value for the chain id is 1337 (ganache's chain id).
Both Ganache and Hardhat support eth_chainId, so maybe MetaMask could use that method to get the correct chain id?
Also note that if you run ganache changing its chain and network ids it doesn't fail, as ganache doesn't implement EIP155.
You can try it with npx ganache-cli -i 1234 --chainId 1234.
@fvictorio, thank you for confirming that!
We deliberately don't use the eth_chainId return value, for security reasons. I recommend running Hardhat on a different port, and adding it as a new custom network with the correct chain ID.
Since this is working as intended, I will now close this issue.
Can you elaborate on those security concerns, @rekmarks ?
@fvictorio, thank you for confirming that!
We deliberately don't use the
eth_chainIdreturn value, for security reasons. I recommend running Hardhat on a different port, and adding it as a new custom network with the correct chain ID.Since this is working as intended, I will now close this issue.
Having to add a new development network manually would be a regression in developer experience. I think it's worth figuring out a way to make this work to avoid introducing new additional friction
Most helpful comment
Having to add a new development network manually would be a regression in developer experience. I think it's worth figuring out a way to make this work to avoid introducing new additional friction