I'm building a JavaScript application where I'm trying to interact with the Ethereum blockchain using ethers.js. However, I'm encountering an error stating that JsonRpcProvider is not found. This issue is preventing me from deploying a contract.

const { ethers } = require("ethers");

const fs = require("fs");

async function main() {
  const provider = new ethers.providers.JsonRpcProvider(
  const wallet = new ethers.Wallet(

  const abi = JSON.parse(
    fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf-8")
  const bytecode =
    "0x" + fs.readFileSync("./SimpleStorage_sol_SimpleStorage.bin", "utf-8");

  const contractFactory = new ethers.ContractFactory(abi, bytecode, wallet);
  console.log("Deploying, please wait...");
  const contract = await contractFactory.deploy();

  console.log("Contract deployed to address:", contract.address);

  .then(() => process.exit(0))
  .catch((error) => {

Error Message:

TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')
    at main (/path/to/your/file.js:5:41)
    at Object.<anonymous> (/path/to/your/file.js:26:1)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49

I've tried checking my imports and ensuring that ethers.js is properly installed in my project. I've also checked for any typos in the code and verified that the necessary dependencies are included in my package.json file.

I'm using yarn as my package manager, and my package.json file includes the necessary dependencies for ethers.js and fs. I've also ensured that the contract ABI and bytecode files exist in the specified paths.

  "name": "ethers-simple-storage-example",
  "version": "1.0.0",
  "license": "MIT",
  "dependencies": {
    "ethers": "^6.12.1",
    "fs": "^0.0.1-security",
    "solc": "^0.8.25"
  "scripts": {
    "compile": "yarn solcjs --bin --abi --include-path node_modules/ --base-path . -o . SimpleStorage.sol"

this error

2 Answers 2


Since you’re using ethers.js v6 (6.12.1), you’ve to access it like:

const provider = new ethers.JsonRpcProvider("");

P.S., The way you’re currently doing is applicable to ethers.js v5.

  • that's work with V5 but Ganache is not detected reason is "could not detect network" in terminal Commented May 15 at 13:45
  • Is your Ganache node running? Commented May 15 at 17:02

Make sure your local Ethereum node (like Geth or Ganache) is running and listening on port 7545 as you are specifying the URL of your local Ethereum node in your program as ""

  • If you are using Ganache, it usually has a GUI which provides information on which port the node is running at
  • If you are using Geth, you should be able to see the console output indicating it's running and listening on port 7545.
  • that's work with ether V5 but Ganache is not detected reason is "could not detect network" in terminal and Ganache is not worke with windows priorly?? Commented May 15 at 13:47

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.