Metamask Not Connecting to Localhost 8545

I was trying to follow a tutorial from devto.io and to send transactions to the smart contract, I would need to connect my MetaMask wallet using one of the accounts created when I ran npx hardhat node command. To do so, I opened MetaMask and updated the network to be Localhost 8545, but Metamask didn't connect to it and showed errors like the following screenshot.

0

3 Answers

I think that you probably interrupted the node you launched when you typped :

npx hardhat node

You should keep it running, open another terminal for the rest of the tutorial. Also you could check the output of this command. Is it indicating something else than ? :

Started HTTP and WebSocket JSON-RPC server at 
4

You probably have a IPv6 address that is not listening on that port.

e.g.

$ ping localhost
PING localhost.localdomain (::1)...

either remove that line from /etc/hosts (e.g. ::1 localhost.localdomain localhost) or point ethermask to 127.0.0.1 instead of localhost

The error is most simple that you probably think, the default chain id for test networks in metamask is not the same as the hardhat chain id, you should go to metamask, then config, networks, localhost and change chain id to 31337

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest