I put my private key in .env file and then import the .env file using require("dotenv").config() but still it is not compiling the code and throws an error. I even installed the dotenv using "yarn add dotenv". In .env file, I put my private key as: PRIVATE_KEY = "(private-key)";
In const wallet, I call the private key as : process.env.PRIVATE_KEY
const ethers = require("ethers");
const fs = require("fs-extra"); //To import the 'fs' fuctionality of node.js to read the files of abi and bytecode
require("dotenv").config();
async function main() {
await console.log("Smart contract address : 0x123456....");
//include the provider and connect the local blockchain to our script
const provider = new ethers.providers.JsonRpcProvider(
"RPC-URL"
);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const abi = fs.readFileSync("./Fundme_sol_Storage.abi", "utf8");
//Here we've included our abi file and it readFileSync mainly takes two arguments obviously one is path of abi file and another is encoding for the smart contract
const byteCode = fs.readFileSync("./Fundme_sol_Storage.bin", "utf8");
//Now we have to use contract factory to deploy the smart contract on our local blockchain
const contractFactory = new ethers.ContractFactory(abi, byteCode, wallet);
console.log("Contract is deploying.....");
const contractDeploy = await contractFactory.deploy();
await contractDeploy.deployTransaction.wait(1);
//This is going to give the number....
const contractRet = await contractDeploy.retrieve();
console.log(contractRet.toString());
//This is going to increement the number..
const contractStore = await contractDeploy.store("42");
await contractStore.wait(1);
//Now, we're going to retrieve number..
const newNum = await contractDeploy.retrieve();
console.log(`The update Fav number is:${newNum}`);
This is the error I am getting in terminal while deploying the code.