TypeError: Cannot read properties of undefined (reading 'readFileSync') #5594
-
I'm following along the code with the video and I am getting the error that I have mentioned in the title. const { ethers } = require('ethers');
const { fs } = require('fs');
async function main() {
const provider = new ethers.providers.JsonRpcProvider(
'HTTP://127.0.0.1:7545'
);
const wallet = new ethers.Wallet(
'0x95afddd0fc571611c2c4a0d17d3978434ddf672c17dae2dc0990ee1ce4d3c173',
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 contract...');
const contract = await contractFactory.deploy();
console.log(contract);
} And {
"dependencies": {
"ethers": "^5.6.8",
"fs-extra": "^11.1.1",
"solc": "^0.8.20"
},
"scripts": {
"compile": "yarn solcjs --bin --abi --include-path node_modules/ --base-path . -o . SimpleStorage.sol"
}
} Any help would be appreciated as to why I am getting this error. |
Beta Was this translation helpful? Give feedback.
Answered by
affanmustafa
Jun 2, 2023
Replies: 1 comment
-
I figured it out. I was destructuring |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
affanmustafa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I figured it out. I was destructuring
fs
inconst { fs } = require('fs');
. The curly brackets aroundfs
are not needed.