Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable using Hardhat network without changing the localhost:8545 chain ID #10290

Open
fvictorio opened this issue Jan 26, 2021 · 53 comments
Open

Comments

@fvictorio
Copy link

I'm opening this issue as suggested by @rekmarks: #9827 (comment)

MetaMask comes with a localhost:8545 network, typically used for development. This network used to work fine both with ganache and with hardhat, but now MetaMask checks that the connected network has 1337 as its chainId. Since Hardhat uses 31337 as its chainId, users get an EIP-155 error when trying to use MetaMask.

The solution is to manually change the project's configuration so that 1337 is used as chainId. This causes unnecessary friction.


I don't know what the correct solution would be here. I think users starting a node on their localhost are knowledgeable enough, and so accepting the chain id returned by the node seems fine in that scenario (unlike manually added networks, where users could be adding by following malicious instructions). But any approach that makes MetaMask work out of the box with Hardhat would be great.

@tuler
Copy link

tuler commented Jan 27, 2021

Another alternative is to create an additional network at MetaMask, name it localhost, use the address http://127.0.0.1:8545, and chainId 31337.

@aeither
Copy link

aeither commented Mar 19, 2021

I got error Could not fetch chain ID. Is your RPC URL correct? when trying to create an additional network at metamask.

image

@praveen-palanisamy
Copy link

praveen-palanisamy commented Apr 1, 2021

@aeither : Use http://0.0.0.0:8545 (instead of http://127.0.0.1:8545) as the RPC URL and try again

adamdry added a commit to adamdry/hardhat that referenced this issue Apr 6, 2021
The original GitHub issue linked has been closed, and a new one has been opened to support HH out of the box.

Old value: MetaMask/metamask-extension#9827
New value: MetaMask/metamask-extension#10290.

This PR updates the link to point to the new issue.
@IMPWNG
Copy link

IMPWNG commented Apr 26, 2021

@aeither : Use http://0.0.0.0:8545 (instead of http://127.0.0.1:8545) as the RPC URL and try again

That still don't work for me ..

@trozler
Copy link

trozler commented Aug 6, 2021

Can we please fix this created unnecessary friction for developers!

@giorgosn
Copy link

Is there any progress on this issue??

@rekmarks rekmarks changed the title Add support for Hardhat Network Enable using Hardhat network without changing the localhost:8545 chain ID Aug 31, 2021
@rekmarks
Copy link
Member

Alright, we're gonna try to do something about this. I can't talk about dates or specifics yet, but hopefully in an upcoming sprint. Our hope is to effectively restore the chain ID behavior for localhost networks (and only localhost networks) to what it was prior to 8.1.0.

By way of context, the change that implemented the current behavior was introduced in version 8.1.0 of the extension, in order to resolve the security vulnerability referenced here: #9827 (comment)

Thank you for your patience and consistent feedback on this issue. We will let you know when we have more information to share, or simply close this issue when we've merged a fix.

@eniolasonowo
Copy link

We are waiting metamask?

@codingwithdidem
Copy link

Any progress?

@fvictorio
Copy link
Author

@eniolasonowo @codingwithdidem please don't do that. We all want this to happen, but these things take time. Erik didn't mention dates for a reason. Just be patient.

@DoubleOTheven
Copy link

Would love a fix for this!

@loziniak
Copy link

loziniak commented Jan 4, 2022

@eniolasonowo @codingwithdidem please don't do that. We all want this to happen, but these things take time. Erik didn't mention dates for a reason. Just be patient.

It's probably because of Hardhat's documentation: "Please voice your support for MetaMask to fix this [...]"

@fvictorio
Copy link
Author

@loziniak in the context of GitHub issues that means upvoting an issue to help maintainers figure out how important it is. But you're right that it could be misleading, I'll update it.

@estainit
Copy link

MetaMask! fix this

@estarossa0
Copy link

updates ?

@Addis-Belete
Copy link

Any updates??

@crazyrabbitLTC
Copy link

Still suffering with this.

@drortirosh
Copy link

Any progress on this? indeed, annoying

@HamasAli
Copy link

Any updates?

@OoXooOx
Copy link

OoXooOx commented Jul 5, 2022

cmon guys, do something

@luislucena16
Copy link

luislucena16 commented Jul 10, 2022

Hey guys! I have found a solution, you must pass directly the chainId:1337 inside the hardhat.config.js file. I have tried it and it worked for me, it stopped sending me the chainId error. I hope it works for you.

e.g

require("@nomicfoundation/hardhat-toolbox");

// The next line is part of the sample project, you don't need it in your
// project. It imports a Hardhat task definition, that can be used for
// testing the frontend.
require("./tasks/faucet");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.9",
  networks: {
    hardhat: {
      chainId: 1337 // We set 1337 to make interacting with MetaMask simpler
    }
  }
};

@luislucena16
Copy link

@Justice-Orogun review my comment

@luislucena16
Copy link

@Justice-Orogun use 31337 in your MetaMask ChainID

@Justice-Orogun
Copy link

@Justice-Orogun review my comment
I just checked.... I am still having the same issue... Didn't work out....

@Justice-Orogun
Copy link

@luislucena16
The same issue bro.... I did that before changing the ChainId to 1337.

@luislucena16
Copy link

like this
like this 2

@Justice-Orogun This is how I have mine and it works fine..

@Justice-Orogun
Copy link

@luislucena16 lemme check this out if it works from my end. Thanks for the feedback

@Justice-Orogun
Copy link

@luislucena16 this is what I have on my end.... However, lemme check out your method.
config

@Justice-Orogun
Copy link

@luislucena16 The same error bro.....
error3

@luislucena16
Copy link

@Justice-Orogun I don't understand why the error is still occurring. It works fine for me

@luislucena16
Copy link

@Justice-Orogun Are you running the npx hardhat node command? Before importing the localhost?

@Justice-Orogun
Copy link

@luislucena16 I already run the npx hardhat node command

@luislucena16
Copy link

luislucena16 commented Nov 29, 2022

@Justice-Orogun Now try adding the localhost network

@Justice-Orogun
Copy link

@luislucena16 The same error..... I just did everything again from scratch....

@hernandp
Copy link

hernandp commented Dec 6, 2022

Same error, please fix this. This is unbelievable.

@Justice-Orogun
Copy link

@hernandp I feel this has to do with Metamask and hardhat... I am very sure there are errors somewhere around it....

@smart-tech-master
Copy link

same error

@G33kNoob
Copy link

i got working

image

@2023PHOENIX
Copy link

@Justice-Orogun i am using same version as you but when i switched to 0.8.16 it start working fine

@cosmic-boy0111
Copy link

that issue get solved before as I know the 31337 error and save button are not visible all things are get solved
before doing all these things run "npx hardhat node" command in your terminal and all is done

@hammad-ali18
Copy link

I want my localhost HARDHAT network to be added by calling wallet_addEthereumChain, when I am passing the chainId inside params of 31337 the calling that the function on the UI,the chainId it is showing me of 201527.
The Error is:
OnMETAMASK:
Chain ID returned by the custom network does not match the submitted chain ID.
and On Console:
inpage.js:1 MetaMask - RPC Error: Unrecognized chain ID "0x31337". Try adding the chain using wallet_addEthereumChain first. {code: -32603, message: 'Unrecognized chain ID "0x31337". Try adding the chain using wallet_addEthereumChain first.', data: {…}}

@luislucena16
Copy link

luislucena16 commented Sep 26, 2023

@hammad-ali18 try this:
#10290 (comment)
configure your UI to receive the chainID you set up

@SL-BLACK-EAGLE
Copy link

hi all, they these steps -

  1. run the node - npx hardhat node
  2. compile the contract - npx hardhat compile
  3. then you have to deploy the smart contract by - 'npx hardhat run scripts/deploy.js'
  4. check the terminal if successful ,
  5. then you can try the metamask localhost wallet. it might fix the issue.
Screen Shot 2023-10-21 at 12 10 30

@GastonFavre
Copy link

With the manual configurations described in previous comments it is possible to address the problem, but it would be great if MetaMask could fix this for immediate operation with Hardahat.

@thunder1911
Copy link

does the above solutions work for sepolia too?

@luislucena16
Copy link

@thunder1911 with sepolia you have no problem!

@thunder1911
Copy link

@thunder1911 with sepolia you have no problem!

No I'm getting the same error when I'm trying to deploy my contract based on sepolia to tha localhost.

@thunder1911
Copy link

@thunder1911 with sepolia you have no problem!

Can we use the same solution given above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests