MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
11.66k stars 4.78k forks source link

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

Open fvictorio opened 3 years ago

fvictorio commented 3 years ago

I'm opening this issue as suggested by @rekmarks: https://github.com/MetaMask/metamask-extension/issues/9827#issuecomment-767098953

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

IMPWNG commented 3 years ago

@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 commented 2 years ago

Can we please fix this created unnecessary friction for developers!

giorgosn commented 2 years ago

Is there any progress on this issue??

rekmarks commented 2 years ago

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: https://github.com/MetaMask/metamask-extension/issues/9827#issuecomment-767098953

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 commented 2 years ago

We are waiting metamask?

codingwithdidem commented 2 years ago

Any progress?

fvictorio commented 2 years ago

@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 commented 2 years ago

Would love a fix for this!

loziniak commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

MetaMask! fix this

estarossa0 commented 2 years ago

updates ?

Addis-Belete commented 2 years ago

Any updates??

crazyrabbitLTC commented 2 years ago

Still suffering with this.

drortirosh commented 2 years ago

Any progress on this? indeed, annoying

HamasAli commented 2 years ago

Any updates?

OoXooOx commented 2 years ago

cmon guys, do something

luislucena16 commented 1 year ago

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
    }
  }
};
Limore0129 commented 1 year ago

@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 ..

it worked for me

Banksy-said-hi commented 1 year ago

Hi all

Is there a solution to this issue? I'm having the same problem with my script.

Have to mention that my ABI is reached correctly, My contract has been deployed successfully and its address is correctly entered in my script. The only assumption I can make is that the Metamask extension cannot connect properly to the network that I have deployed my project on by running "npx hardhat run scripts/deploy.js" which deploys the project to the hardhat localhost.

Unhandled Runtime Error
Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="fetchMarketItems()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)
Justice-Orogun commented 1 year ago

Guys, this thing is not working from my end. I already tried all the options here, it keep throwing back the same error. Could I be doing something wrong?

Justice-Orogun commented 1 year ago

hardhat error1

Justice-Orogun commented 1 year ago

error2 It is all the same..... I even changed the chainId to 1337 in the config.js file, it is all the same

luislucena16 commented 1 year ago

@Justice-Orogun review my comment

luislucena16 commented 1 year ago

@Justice-Orogun use 31337 in your MetaMask ChainID

Justice-Orogun commented 1 year ago

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

Justice-Orogun commented 1 year ago

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

luislucena16 commented 1 year ago

like this like this 2

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

Justice-Orogun commented 1 year ago

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

Justice-Orogun commented 1 year ago

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

Justice-Orogun commented 1 year ago

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

luislucena16 commented 1 year ago

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

luislucena16 commented 1 year ago

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

Justice-Orogun commented 1 year ago

@luislucena16 I already run the npx hardhat node command

luislucena16 commented 1 year ago

@Justice-Orogun Now try adding the localhost network

Justice-Orogun commented 1 year ago

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

hernandp commented 1 year ago

Same error, please fix this. This is unbelievable.

Justice-Orogun commented 1 year ago

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

smart-tech-master commented 1 year ago

same error

G33kNoob commented 1 year ago

i got working

image

2023PHOENIX commented 1 year ago

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

cosmic-boy0111 commented 1 year ago

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 commented 9 months ago

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 commented 9 months ago

@hammad-ali18 try this: https://github.com/MetaMask/metamask-extension/issues/10290#issuecomment-1329960809 configure your UI to receive the chainID you set up

SL-BLACK-EAGLE commented 8 months ago

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 commented 6 months ago

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 commented 3 months ago

does the above solutions work for sepolia too?