-1
const ethers = require("ethers");
const fs = require("fs-extra");

async function main() {
  // http://127.0.0.1:7545
  // Compile in our code
  // Compile them seperately
  const provider = new ethers.JsonRpcProvider("http://127.0.0.1:7545");
  const wallet = new ethers.Wallet(
    "0x578f756dd1e637bb78dff004cff8517f384f3be491cce3147e4a4f53bcbb8396",
    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);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

The Error is:

JsonRpcProvider failed to `startup; retry in 1s Error: connect ECONNREFUSED 127.0.0.1:7545 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 7545

I thought maybe port 7545 was closed so I ran the netstat command and it seems to be open and listening. I'm a little lost. Any help is much appreciated!

  • This is what I got from the netstat command: [Ganache.exe] TCP 127.0.0.1:51068 DEV33:7545 ESTABLISHED [Ganache.exe] TCP 127.0.0.1:51073 DEV33:7545 ESTABLISHED [Ganache.exe] TCP 127.0.0.1:51074 DEV33:7545 ESTABLISHED [Ganache.exe] TCP 172.17.144.1:139 DEV33:0 LISTENING – LoganL33 Mar 15 '23 at 02:52

4 Answers4

1

My Problem Is solve by changing the ganache server to wifi and try this port 8545; First Change the ganache server by go to setting and then go to server tab. and try this port with jsonRpcProvider function/ http://192.168.100.9:8545 Try This And You Error Will Be Fixed.

Mike Szyndel
  • 10,461
  • 10
  • 47
  • 63
1

On Mac m2 on Ventura OS, in the Ganache app, go to settings -> server -> change the hostname of the Ganache server to 192.168.10.128. screenshot

Alvin Lim
  • 11
  • 2
0

for anyone who is taking the free code camp / pat collins course (or anyone on a WSL + Ganache setup really) you're going to want to edit the ganache server settings (top right gear icon>server tab) to go by vEthernet http://172.24.240.1 so your ganache and ethers can connect

Flasgod
  • 101
  • 2
0

As a fork of Flasgod's answer:

I am working through the free code camp / pat collins course and I'm working in the WSL environment.

Switching to the vEthernet server inside of ganache (top right gear icon>server tab) did not work for me. I believe this is because I am trying to run my deploy code inside the WSL: Ubuntu environment while ganache is running on my Windows desktop. They couldn't connect to each other.

Solution:

  • Follow these directions from the truffle/ganache github to install and use ganache in the WSL command line.
    • This way, ganache is running inside the WSL environment along side the deploy code.
  • run ganache in the WSL command line.
  • Use the private key and "listening on" ip displayed in the terminal.
    • ip should still be formatted "http://x.x.x.x:xxxx" in the code.
  • Open up a new terminal window so ganache continues to run in the first window.
  • run node deploy.js

This solved my problem.