ganache
ganache copied to clipboard
Specifying `"localhost"` in `server.listen` does not work.
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.
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.
@gluax what OS are you running? @AbnerZheng what OS are you running?
I'm running on Windows 10.
I'm running on macos.
This may be related to this Node bug: https://github.com/nodejs/node/issues/40702
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.
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.