Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Could Not Detect Network on deploy.js - WSL & Ganache #34

Answered by LetsBuildAndCreate
Equious asked this question in Q&A
Discussion options

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.

You must be logged in to vote

This is what worked for me 👍

OPTION 1: If you want to install & run Ganache on your WSL itself👇

  1. Install Ganache on WSL
    yarn add ganache

  2. Run Ganache
    yarn run ganache

  3. 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.

  4. Also copy any Private key on scrolling up the Terminal Screen & paste it in the ethers.js Wallet( ) function parameter.

  5. 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

Comment options

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.

You must be logged in to vote
1 reply
Comment options

Hmm, it shouldn't matter, but I have tried both to no avail. Appreciate the reply!

Comment options

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.

  1. Run npm install ganache on Terminal. Check if it is install correctly by run ganache --version
  2. Run ganache on terminal, you will see many information include private keys and RPC showing. Put one of private key and RPC in deploy.js
  3. Open new terminal and run node deploy.js
  4. Check your ganache terminal again and you should see transaction appear.
You must be logged in to vote
47 replies
Comment options

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.

Comment options

thank you ! it really works !

Comment options

Thank you, this question has been bothering me for a long time

Comment options

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 :)

Comment options

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?

Comment options

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:

  1. 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
  1. Make it executable chmod +x ganache-2.5.4-linux-x86_64.AppImage
  2. Run it ./ganache-2.5.4-linux-x86_64.AppImage

Voila! 🥳

You must be logged in to vote
6 replies
Comment options

No idea. But make sure you've uninstalled any other Ganache, then try to install this.

Comment options

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 directory after 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.

Comment options

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 directory after 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?

Comment options

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

Comment options

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

Comment options

No problem! Feel welcome to join the Discord I set up for folks going through this! https://discord.gg/CtMVfhuV
...
On Fri., Jun. 24, 2022, 6:08 a.m. a14i12, ***@***.***> wrote: @Equious <https://github.com/Equious> thanks a lot bud i was completely lost on this!! — Reply to this email directly, view it on GitHub <#34 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ASHIK5BDOTNWRHMKDGA4273VQWQMHANCNFSM5XIPYCGQ> . You are receiving this because you were mentioned.Message ID: <smartcontractkit/full-blockchain-solidity-course-js/repo-discussions/34/comments/3017239 @github.com>
You must be logged in to vote
5 replies
Comment options

awesome...was looking for something like this

Comment options

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)

Comment options

same issue with me. How to resolve this?

Comment options

If you are using yarn, try "yarn run ganache"

Comment options

Thanksyarn run ganacheworks as ganache was not working

Comment options

Looks like the Link JUST expired today, here's a new one https://discord.gg/CtMVfhuV
...
On Fri., Jun. 24, 2022, 9:05 a.m. mariusdique, ***@***.***> wrote: 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) — Reply to this email directly, view it on GitHub <#34 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ASHIK5EGK6WDACHU5JSHLZDVQXFD3ANCNFSM5XIPYCGQ> . You are receiving this because you were mentioned.Message ID: <smartcontractkit/full-blockchain-solidity-course-js/repo-discussions/34/comments/3018299 @github.com>
You must be logged in to vote
2 replies
Comment options

Remember, you can edit your comments :)

Comment options

@Equious could you send me the ds link again please?

Comment options

You have to run ganache as "yarn run ganache" in the terminal.
...
On 2022年7月14日 at 4:41 AM, Madhav ***@***.***> wrote: Guys I have tried all the things , i have installed ganache on the windows in terminal yarn add ganache , but when i am typing ganache --version , it is showing me command not found , I have also installed ganache on the desktop as application , but again it when i am deploying wiht node ../deploy.js , it is giving error "Could not detect network" Any Help please — Reply to this email directly, view it on GitHub <#34 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAI7UCKTMPEXW7HCUS5BVSDVT6D5JANCNFSM5XIPYCGQ> . You are receiving this because you commented.Message ID: <smartcontractkit/full-blockchain-solidity-course-js/repo-discussions/34/comments/3142810 @github.com>
You must be logged in to vote
1 reply
Comment options

loool thanks mate! this actually just saved me <3

Comment options

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.

ganache-firewall

  • Select Inbound Rules.
  • Select Ganache, right-click and go to Properties.
  • Allow the connection and Apply.
  • Repeat for the rest, if any.
You must be logged in to vote
1 reply
Comment options

Thank you !!!!

Comment options

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.

You must be logged in to vote
4 replies
Comment options

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
);

Comment options

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!

Comment options

use hostname as -Ethernet WSL
and check your windows defender inbound rules=>allow;
it will work for sure.

Comment options

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'
 }
 }
Comment options

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!

You must be logged in to vote
8 replies
Comment options

best answer :)

Comment options

Life Saver, thank you !!!!!!!!!!!!!!!

Comment options

Thank you so much! It's worked

Comment options

It worked!!!!!!!

Comment options

I appreciate you.
You just saved me from giving up this part.
Thank you very much! 👍

Comment options

This is what worked for me 👍

OPTION 1: If you want to install & run Ganache on your WSL itself👇

  1. Install Ganache on WSL
    yarn add ganache

  2. Run Ganache
    yarn run ganache

  3. 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.

  4. Also copy any Private key on scrolling up the Terminal Screen & paste it in the ethers.js Wallet( ) function parameter.

  5. 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 )👇

  1. 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.

  2. Click on Save & Restart at the top right hand corner of the UI.

  3. Now Copy the RPC URL from the RPC SERVER and paste it in the ethers.js JsonRpcProvider( ) function parameter.

  4. Also Copy any Private Key and paste it in the ethers.js Wallet( ) function parameter.

  5. 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.

  6. 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. ✌

You must be logged in to vote
38 replies
Comment options

Thank you so much

Comment options

couldn't proceed further bcoz of this issue. Thanks a lot's

Comment options

We are going to remove ganache in the next big update. Sorry about this all!

Comment options

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

Comment options

I have the same bug...

Answer selected by PatrickAlphaC
Comment options

thanks very much! it works.

You must be logged in to vote
1 reply
Comment options

Thank you very much for this contribution option 2 worked for me

Comment options

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 🎉🧨🎊

You must be logged in to vote
0 replies
Comment options

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);
 })
You must be logged in to vote
0 replies
Comment options

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
You must be logged in to vote
0 replies
Comment options

Use gpt 04 mini high model.
...
On 2025年4月20日, 7:34 pm Chiefilion, ***@***.***> wrote: 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.png (view on web) <https://github.com/user-attachments/assets/802fb267-79b2-4d09-be96-efd9911f3f80> Screenshot.2025年04月20日.194017.png (view on web) <https://github.com/user-attachments/assets/fe692225-f3b3-4457-8b82-b42fe636cc1f> Screenshot.2025年04月20日.194028.png (view on web) <https://github.com/user-attachments/assets/45d3e180-3268-421c-aada-94ece62251a6> — Reply to this email directly, view it on GitHub <#34 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BC224NRXWLUYIPHUOURPARL22OV65AVCNFSM6AAAAAB3PZD7GSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEOBZGA3TOOA> . You are receiving this because you commented.Message ID: <smartcontractkit/full-blockchain-solidity-course-js/repo-discussions/34/comments/12890778 @github.com>
You must be logged in to vote
0 replies
Comment options

🛠️ 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

  1. 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.
  2. On Windows CMD:

    • Open Command Prompt.
    • Type ipconfig and hit Enter.
    • Look for your IPv4 address (usually something like 192.168.x.x) and copy it.
  3. In WSL (Ubuntu side):

    • Open your project in VS Code (WSL).
    • Update your .env file like this:
      RPC_URL=http://<your_ipv4_address>:8555
      Replace <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!

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /