const { ethers } = require("ethers");
const { fs } = require("fs-extra");
require("dotenv").config();
async function main() {
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8");
let wallet = new ethers.Wallet.fromEncryptedJsonSync(
encryptedJson,
process.env.PRIVATE_KEY_PASSWORD
);
wallet = await wallet.connect(provider);
const abi = readFileSync(
"./hh-fcc/ethers-simple-storage_SimpleStorage_sol_SimpleStorage.abi",
"utf8"
);
const binary = readFileSync(
"./hh-fcc/ethers-simple-storage_SimpleStorage_sol_SimpleStorage.bin",
"utf8"
);
const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
console.log("Deploying, please wait...");
const contract = await contractFactory.deploy();
await contract.deployTransaction.wait(1);
const currentFavoriteNumber = await contract.retrieve();
console.log(`Current Favorite Number: ${currentFavoriteNumber.toString()}`);
const transactionResponse = await contract.store("7");
const transactionReceipt = await transactionResponse.wait(1);
const updatedFavoriteNumber = await contract.retrieve();
console.log(`Updated favorite number is: ${updatedFavoriteNumber}`);
}
main() // code for waiting the above code to finish
.then(() => process.exit(0)) //and then print any errors
.catch((error) => {
console.error(error);
process.exit(1);
});
`For the above code I’m getting the error as: TypeError: Cannot read properties of undefined (reading ‘readFileSync’)
Based on the other solutions on stackoverflow I have lowered the version of ethers which solved the bug but ended up to this line of error`
New contributor
Abhinav Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.