question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specifying `"localhost"` in `server.listen` does not work.

See original GitHub issue

The following does not work but likely should mimic common behavior between other js libs.

 let server = Ganache.server();
server.listen(8888, 'localhost');

There’s no direct error and everything seems to function. However, after deploying a contract and trying to make calls to it(at least with the ethers lib from my own testing) results in an Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.6.8).

However, the following works as expected.

 let server = Ganache.server();
server.listen(8888, '127.0.0.1');

For consistency/commonly thought of behavior 'localhost' should provide the same behavior as directly writing out the localhost address.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benjamincburnscommented, Nov 15, 2022

Assuming that the issue is caused by nodejs/node#40702, you may find that the problem abates on node 16.x.x. You may also find that if you check the output of lsof -i -P | grep LISTEN | grep 8545, the node process that hosts ganache will be listening on IPv6 (usually the 5th column in the output).

We just encountered and fixed what’s likely the same issue with the Truffle dashboard. I wrote up a fairly in-depth explanation of the problem on the related issue at trufflesuite/truffle#5690, and the fix can be seen at trufflesuite/truffle#5699.

0reactions
OnlyOneJMJQcommented, Nov 15, 2022

I think this is related, on my machine (which, for context, produced the error @benjamincburns is referencing) if I run ganache on localhost and my truffle-config is set to 127.0.0.1 I get the error:

Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 8888
    - network_id > *

If I change my truffle-config to use localhost as well, then it will work. This leads me to believe it is the IP resolution issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

express app server . listen all interfaces instead of localhost only
If you don't specify host while calling app.listen, server will run on all interfaces available i.e on 0.0.0.0. You can bind the IP...
Read more >
Localhost Refused to Connect Error: 5 Confirmed Ways to Fix It
Localhost refused to connect error can be caused by an incorrectly configured port, insufficient permissions, or an inoperative web server.
Read more >
"Server is not listening on port 3000" but application is running.
Got this issue with express@4.16.1. I figured out that it was because the usage of app.listen() in app.js and "node /bin/www" in package.json ......
Read more >
Can't connect to node HTTP server running on localhost
I'm trying to write an integration test which for now simply launches a Node server, then queries it to check if it's running...
Read more >
How to listen on port 80 with Node.js ? - GeeksforGeeks
Specify Port Number and hostname and set the server to listen to it. server.listen(port,hostname,callback);. What happens when we listen to port ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found