-
Couldn't load subscription status.
- Fork 3.3k
Could Not Detect Network on deploy.js - WSL & Ganache #34
-
const provider = new ethers.providers.JsonRpcProvider( "HTTP://127.0.0.1:8545" );
Error:
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
My Ganache UI is running. I assume this has something to do with WSL/Ubuntu .. I've never used the linux side of anything before >.>. I tried setting my Host Name to 0.0.0.0 (All Interfaces) and reflecting that in my script, but there was no change.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 4
This is what worked for me 👍
OPTION 1: If you want to install & run Ganache on your WSL itself👇
-
Install Ganache on WSL
yarn add ganache -
Run Ganache
yarn run ganache -
Copy the RPC URL (127.0.0.1:8545) from the bottom of the terminal screen that says RPC listening on 127.0.0.1:8545
& paste it in the ethers.js JsonRpcProvider( ) function parameter. -
Also copy any Private key on scrolling up the Terminal Screen & paste it in the ethers.js Wallet( ) function parameter.
-
Now let this terminal run in the background, since we want our Ganache server to be running.
So open a new terminal & run the deploy.js file by running the below command:
node deploy.js
OPTION 2: If you want to run Ga...
Replies: 16 comments 114 replies
-
I'm not sure if this would help, but maybe you can try making the HTTP lower case -> http. Sometimes there can be errors with capitalization.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hmm, it shouldn't matter, but I have tried both to no avail. Appreciate the reply!
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 4
-
Because you use WSL but Ganache UI opened is on Windows. You need to install ganache on WSL first then run the ganache server on WSL after that you can deploy on network. Here is the steps.
- Run
npm install ganacheon Terminal. Check if it is install correctly by runganache --version - Run
ganacheon terminal, you will see many information include private keys and RPC showing. Put one of private key and RPC in deploy.js - Open new terminal and run
node deploy.js - Check your ganache terminal again and you should see transaction appear.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 22 -
🚀 5
-
My ganache UI is not working. I am using ganache terminal but every time I use yarn run ganache the transaction resets and I get new wallets. Is there a way to check previous transactions and not get new wallets?
@BlueAdmiral Just type yarn run ganache in terminal, replace private key and RPC Server in the contract from the available wallets and open new terminal(you could see a + button in the top right corner of existing terminal) and run deploy.js. It should work.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2 -
😄 1 -
❤️ 3
-
thank you ! it really works !
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you, this question has been bothering me for a long time
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you for your help! I tried a lot of things and it still didn't work until I saw your solution to solve the problem :)
Beta Was this translation helpful? Give feedback.
All reactions
-
This solution partially worked for me. After running yarn run ganache I get an error stating "This version of μWS is not compatible with your Node.js build". However after this error it still manages to deploy accounts with fake ether. What version of node.js should I use for this to work, I realize this issue was raised 2 years ago. Should I change my node.js version or keep it up to date while using an alternative method to connect through WSL?
Beta Was this translation helpful? Give feedback.
All reactions
-
Actually if you're running WSL 2, you can install & run Ganache(GUI) natively. And can simply use it; as it's actually installed on the Linux.
Steps to run:
- Download the latest *.AppImage from https://github.com/trufflesuite/ganache-ui/releases
wget https://github.com/trufflesuite/ganache-ui/releases/download/v2.5.4/ganache-2.5.4-linux-x86_64.AppImage
- Make it executable
chmod +x ganache-2.5.4-linux-x86_64.AppImage - Run it
./ganache-2.5.4-linux-x86_64.AppImage
Voila! 🥳
Beta Was this translation helpful? Give feedback.
All reactions
-
No idea. But make sure you've uninstalled any other Ganache, then try to install this.
Beta Was this translation helpful? Give feedback.
All reactions
-
trying this, but getting
tmp/.mount_ganach8Dr7O1/Ganache: error while loading shared libraries: libXcursor.so.1: cannot open shared object file: No such file or directoryafter step 3. Any suggestions? :(
Hi if you are still having issues with this then there is simple way to do it. You just need to install the name of the library. I did a bit of digging and discovered that Windows Subsystem for Linux doesn't come with the required libraries to run an executable. I had to download 7-8 libraries and got to fix the issue.
Beta Was this translation helpful? Give feedback.
All reactions
-
trying this, but getting
tmp/.mount_ganach8Dr7O1/Ganache: error while loading shared libraries: libXcursor.so.1: cannot open shared object file: No such file or directoryafter step 3. Any suggestions? :(Hi if you are still having issues with this then there is simple way to do it. You just need to install the name of the library. I did a bit of digging and discovered that Windows Subsystem for Linux doesn't come with the required libraries to run an executable. I had to download 7-8 libraries and got to fix the issue.
What libraries did you install?
Beta Was this translation helpful? Give feedback.
All reactions
-
this does work! but it does not work for those who have the WSL1 version and they must have it in WSL2 and reinstall the linux operating system that is running it again
Beta Was this translation helpful? Give feedback.
All reactions
-
this does work! but it does not work for those who have the WSL1 version and they must have it in WSL2 and reinstall the linux operating system that is running it again
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
awesome...was looking for something like this
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks mate but it tells me the invitation is invalid. In my case Itried with the npm and also the yarn way. But I am not able to see the ganache version. (ganache: command not found)
Beta Was this translation helpful? Give feedback.
All reactions
-
same issue with me. How to resolve this?
Beta Was this translation helpful? Give feedback.
All reactions
-
If you are using yarn, try "yarn run ganache"
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Thanksyarn run ganacheworks as ganache was not working
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Remember, you can edit your comments :)
Beta Was this translation helpful? Give feedback.
All reactions
-
@Equious could you send me the ds link again please?
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 5
-
loool thanks mate! this actually just saved me <3
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
If it gets stuck on deploying after changing the hostname in Ganache UI (like this and this), then you have to allow the connection for Ganache in Windows Defender Firewall with Advanced Security.
- Select Inbound Rules.
- Select Ganache, right-click and go to Properties.
- Allow the connection and Apply.
- Repeat for the rest, if any.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 9
-
Thank you !!!!
Beta Was this translation helpful? Give feedback.
All reactions
-
Well, I literally tried each one of these solutions multiple times (over 2+ hours) and was never able to actually run node deploy.js successfully.
I imagine it was user error on my part, and I appreciate everyone's attempt at explaining the solution.
I'm going to try and keep moving forward with the course.
Beta Was this translation helpful? Give feedback.
All reactions
-
I have same problem when you change server setting wsl then your ganache rpc server also changed so this error is coming so replace in your deploy js
eg in my case
const provider = new ethers.providers.JsonRpcProvider(
"http://172.19.112.1:7545" //you get this in your ganache gui
);
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Yeh changing the setting of HOSTNAME from Loopback Pseudo-Interface 1 to vEthernet(WSL) will change your RCP server URL, after replacing this new URL the node deploy.js command gonna work successfully.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions
-
use hostname as -Ethernet WSL
and check your windows defender inbound rules=>allow;
it will work for sure.
Beta Was this translation helpful? Give feedback.
All reactions
-
I use the same way like @hrushigawade24 , it can connect the ganache,
but still get another error
const provider = new ethers.JsonRpcProvider("http://172.25.32.1:7545");
const wallet = new ethers.Wallet(
"0x1b7c58ec21da243cf0bc51a6868c235d7441d6ba0ed2e59a3dbe217c05fc1c7c",
provider
);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const binary = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.bin",
"utf8"
);
const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
console.log("Deploying, please wait...");
const contract = await contractFactory.deploy();
console.log(contract);
I got another problem like this below, and I have no idea about it
Error: missing revert data (action="estimateGas"
........
........
........
info: {
error: {
message: 'VM Exception while processing transaction: invalid opcode',
stack: 'RuntimeError: VM Exception while processing transaction: invalid opcode\n' +
' at exactimate (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\1円.js:2:182136)',
code: -32000,
name: 'RuntimeError',
data: [Object]
},
payload: {
method: 'eth_estimateGas',
params: [Array],
id: 4,
jsonrpc: '2.0'
}
}
Beta Was this translation helpful? Give feedback.
All reactions
-
Following up, this is what worked for me:
I was using Windows 11, WSL2, and GanacheUI installed in windows. When running node deploy.js, I was getting the following error:
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
Must be some kind of firewall issue, but I didn't want to debug the networking, and instead just ran a simple command to run ganache in the terminal of VS code. In the top right corner of the terminal section, click the little plus icon to open a new terminal. Then enter the following:
yarn add ganache
yarn run ganache
copy the local IP address that's printed at the very bottom: "RPC Listening on 127.0.0.1:4444"
Paste that IP into the deploy.js:
const provider = new ethers.providers.JsonRpcProvider(
"http://127.0.0.1:4444"
);
save it, then switch back to the other terminal window that isn't running ganache
node deploy.js
Thanks to the other folks in this thread!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3 -
😄 2 -
🚀 8
-
best answer :)
Beta Was this translation helpful? Give feedback.
All reactions
-
Life Saver, thank you !!!!!!!!!!!!!!!
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you so much! It's worked
Beta Was this translation helpful? Give feedback.
All reactions
-
It worked!!!!!!!
Beta Was this translation helpful? Give feedback.
All reactions
-
I appreciate you.
You just saved me from giving up this part.
Thank you very much! 👍
Beta Was this translation helpful? Give feedback.
All reactions
-
This is what worked for me 👍
OPTION 1: If you want to install & run Ganache on your WSL itself👇
-
Install Ganache on WSL
yarn add ganache -
Run Ganache
yarn run ganache -
Copy the RPC URL (127.0.0.1:8545) from the bottom of the terminal screen that says RPC listening on 127.0.0.1:8545
& paste it in the ethers.js JsonRpcProvider( ) function parameter. -
Also copy any Private key on scrolling up the Terminal Screen & paste it in the ethers.js Wallet( ) function parameter.
-
Now let this terminal run in the background, since we want our Ganache server to be running.
So open a new terminal & run the deploy.js file by running the below command:
node deploy.js
OPTION 2: If you want to run Ganache on your Windows ( if you have already installed Ganache on Windows )👇
-
Go to Settings ( Gear Icon ) on the Top Right hand Corner of Ganache Windows GUI.
Move over to the Server tab and Change the HOSTNAME to WSL ( Mine worked for VirtualBox & WiFi too )
Port Number & Network ID can be LEFT UNHARMED. -
Click on Save & Restart at the top right hand corner of the UI.
-
Now Copy the RPC URL from the RPC SERVER and paste it in the ethers.js JsonRpcProvider( ) function parameter.
-
Also Copy any Private Key and paste it in the ethers.js Wallet( ) function parameter.
-
IMPORTANT STEP ( Firewall Settings ) :
Go to Windows Defender Firewall with Advanced Security on your Windows.
Click on Inbound Rules & Search for Ganache
Right click on Ganache & Go to Properties.
Then Check the CheckBox that says Allow the connection & Click on Apply. And Close this Firewall window. -
Run the deploy.js file by running the command in the WSL terminal window:
node deploy.js
Thanks a lot to All the people answering & also asking their doubts. ✌
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 54 -
🎉 9 -
❤️ 21
-
Thank you so much
Beta Was this translation helpful? Give feedback.
All reactions
-
couldn't proceed further bcoz of this issue. Thanks a lot's
Beta Was this translation helpful? Give feedback.
All reactions
-
We are going to remove ganache in the next big update. Sorry about this all!
Beta Was this translation helpful? Give feedback.
All reactions
-
Could you please help me out because I try to solve this issue quite for a week and still not solved as I followed your steps and my problem is still not solved
Screenshot 2025年04月20日 194005
Screenshot 2025年04月20日 194017
Screenshot 2025年04月20日 194028
Beta Was this translation helpful? Give feedback.
All reactions
-
I have the same bug...
Beta Was this translation helpful? Give feedback.
All reactions
-
thanks very much! it works.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you very much for this contribution option 2 worked for me
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you so much it worked for me I tried for an hour in UI but rejected the gas limit again and again, CLI worked for me 🎉🧨🎊
Beta Was this translation helpful? Give feedback.
All reactions
-
Just updating to help folks, I've done today with latest ethers and all good:
Install Ganache on WSL
yarn add ganache
Run Ganache
yarn run ganache
const ethers = require("ethers") const fs = require("fs") async function main() { const provider = new ethers.JsonRpcProvider("http://127.0.0.1:8545"); const wallet = new ethers.Wallet(`you should change here with one of many available after running run ganache`, provider); console.log('wallet - - - -', wallet.privateKey); const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf-8"); const binary = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.bin", "utf-8"); const contractFactory = new ethers.ContractFactory(abi, binary, wallet); console.log("Deploying, please wait...") const contract = await contractFactory.deploy(); console.log('contract - - -', contract); } main() .then(() => process.exit(0)) .catch(error => { console.error(error); process.exit(1); })
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
If you are late on the course, the problem for me was ethers version and the ganache problem.
Following the tutorial above to run ganache from vscode directly and installing ethers 5.7.0 should solve de problem
npm uninstall ethers
npm install ethers@5.7.0
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
🛠️ How to Fix Ganache RPC Connection Issue Between Windows & WSL
Hey folks! If you're developing on Windows but running your scripts inside WSL (Ubuntu/Linux), you might hit a weird network issue with Ganache — especially around port connections.
Here’s a super simple fix that worked for me:
🔧 Step-by-Step
-
In Ganache (Windows side):
- Open Ganache and go to settings.
- Change the host name to
0.0.0.0. - Set the port number to something like
8555.
-
On Windows CMD:
- Open Command Prompt.
- Type
ipconfigand hit Enter. - Look for your IPv4 address (usually something like
192.168.x.x) and copy it.
-
In WSL (Ubuntu side):
- Open your project in VS Code (WSL).
- Update your
.envfile like this:ReplaceRPC_URL=http://<your_ipv4_address>:8555
<your_ipv4_address>with the one you copied, and match the port with Ganache.
💥 Boom! Problem Solved
Once I made these changes, my script connected to Ganache without any issues. Hope this makes your setup smoother and saves you some debugging time!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1