ganache icon indicating copy to clipboard operation
ganache copied to clipboard

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

Open gluax opened this issue 3 years ago • 4 comments

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.

gluax avatar Aug 03 '22 22:08 gluax

I have tested it, and 'localhost' works in my own desktop.

The mapping from localhost to 127.0.0.1 is done by the hosts file in *nix system, check /etc/hosts,adding one line 127.0.0.1 localhost, it might works.

AbnerZheng avatar Aug 04 '22 16:08 AbnerZheng

@gluax what OS are you running? @AbnerZheng what OS are you running?

davidmurdoch avatar Aug 04 '22 16:08 davidmurdoch

I'm running on Windows 10.

gluax avatar Aug 04 '22 17:08 gluax

I'm running on macos.

AbnerZheng avatar Aug 05 '22 05:08 AbnerZheng

This may be related to this Node bug: https://github.com/nodejs/node/issues/40702

davidmurdoch avatar Nov 15 '22 01:11 davidmurdoch

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.

benjamincburns avatar Nov 15 '22 04:11 benjamincburns

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.

DiscRisknBisque avatar Nov 15 '22 20:11 DiscRisknBisque