smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.4k stars 2.98k forks source link

TypeError: Cannot read properties of null (reading 'constructor') [lesson 5] #5162

Closed Nikhil7174 closed 1 year ago

Nikhil7174 commented 1 year ago

Describe the enhancement

I am getting this error after degrading my ethers from 6 to 5.7.1 in order to solve the RpcProvider issue, can someone please help me?

nikhil123@LAPTOP-MDHK1OE1:~/folder/hh-fcc/ethers-simple-storage$ node deploy.js
TypeError: Cannot read properties of null (reading 'constructor')
    at getStatic (/home/nikhil123/folder/hh-fcc/ethers-simple-storage/node_modules/@ethersproject/properties/lib/index.js:60:53)
    at Object.ContractFactory (/home/nikhil123/folder/hh-fcc/ethers-simple-storage/node_modules/@ethersproject/contracts/lib/index.js:1089:88)
    at main (/home/nikhil123/folder/hh-fcc/ethers-simple-storage/deploy.js:12:36)
    at Object.<anonymous> (/home/nikhil123/folder/hh-fcc/ethers-simple-storage/deploy.js:18:1)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 

My deploy.js

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

async function main() {
    //compile them in our code
    //compile them seperately
    //http://127.0.0.1:7545
    const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:7545");
    const wallet = new ethers.Wallet("0xc4e6ed033bec6c6f706ec870a866ed9e77a4012a468e39bf2f94efb9a092959c",provider);
    const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi","utf8");
    const binary = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.bin","utf8");
    const contractFactory = ethers.ContractFactory(abi,binary,wallet);
    console.log("Deploying, please wait...");
    const contract = await contractFactory.deploy(); //stop here wait for the contract to deploy
    console.log(contract);
}

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

What worked for me was using ethers 6.6.2 only but removing ".providers" from the syntax.

 let provider = new ethers.JsonRpcProvider("http://127.0.0.1:8545");