trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.61k stars 675 forks source link

Connecting MetaMask to remote detached Ganache CLI #4217

Closed gcobr closed 1 year ago

gcobr commented 1 year ago

I am prototyping a DApp, and I would not like to use any of the Ethereum test networks with it for now. Instead, I would like to run a fake blockchain using Ganache on a remote server and connect MetaMask from the user's browser to it.

If I run it in detached mode using something like this

ganache --port=8544 --miner.blockTime=10 --detach

on a remote server, should I be able to connect MetaMask to it as a custom network using an endpoint like http://my.custom.server.domain:8544?

Assume the firewall (which in this case is an AWS security group on the corresponding EC2 instance) allows traffic on port 8544. Is there any other port I would have to open?

I ran a few experiments with the set up above, but it seems that MetaMask can never see the fake ETH balance that the test accounts would have. MetaMask always shows a balance of 0 ETH for all accounts.

Also, any tips for debugging this? Anything in particular I'd have to check in logs?

jeffsmale90 commented 1 year ago

Hi thanks for raising this issue!

The issue is potentially caused by the --server.host parameter which defaults to 127.0.0.1.

Can you please try by starting Ganache with the following:

ganache --port=8544 --miner.blockTime=10 --server.host=0.0.0.0 --detach

In addition, you can try connecting to Ganache directly (cutting out Metamask), by executing the following from your local computer:

curl -s http://my.custom.server.domain:8544 -X POST -H "Content-Type:application/json;" -d '{"id":1,"jsonrpc":"2.0","method":"eth_accounts"}'