2

I have added truffle workspace to Ganache as usual. But now when I do a simple truffle develop followed by migrate inside the truffle shell, Ganache picks up that the contracts are deployed, but it doesn't pickup changes to the wallet balances.

My truffle-config.js files has only one change:

  compilers: {
    solc: {
      version: "native", 
    },
  },

I am running truffle inside WSL2, whereas ganache gui is installed natively in windows.

Below is the balance reported by Truffle shell:

truffle(develop)> web3.eth.getBalance(accounts[0])
'99934183260000000000' # updated balance after migrate

truffle(develop)> accounts[0]
'0x6b318B9350E42bEB94f9Ae5e8b9DA854a6137628'

Where that same account 0x6b318B9350E42bEB94f9Ae5e8b9DA854a6137628 in Ganache shows balance full 100 Eth: image

3 Answers 3

0

I had a similar issue that seem to be fixed by making sure I had ganache-cli running before trying to connect to it in the GUI. I also had to choose the host type of "0.0.0.0"

0

I add the following to my .zshrc or .bashrc file

# Get WSL Host IP
export WSL_HOST_IP="$(awk '/nameserver/ { print $2 }' /etc/resolv.conf)"

This allows me to surface my host ip, so commands in WSL2 can reach the localhost.

Now create a workspace in Ganache GUI and under the server HOSTNAME settings choose "0.0.0.0 - All Interfaces".

In your truffle project edit the truffle-config.js file and set your network development block to this:

development: {
  host: process.env.WSL_HOST_IP,
  port: 7545,
  network_id: "*" // Match any network id
}

Now when you run truffle migrate, it should connect to the Ganache GUI.

-1

Ganache UI under Windows is not the same as Ganache-cli under WSL

The Ganache UI on Windows is listening to Windows Port.

The WSL2 instance have it's own set of ports.

So Even if they are set to the same port they are not

What you should do is use Ganache-cli in WSL2. This will fix your issue. Since they will both be on the same system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.