0

Error:

enter image description here

Code:

const ethers = require("ethers");

const fs = require("fs-extra");
require("dotenv").config();

async function main() {
console.log(process.env.PRIVATE_KEY);
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);

//const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const encryptedJson = fs.readFileSync(
"/media/kalki/030ABB616FC574C0/visualstudio/learnBlockchain/encrypted.json",
"utf8",
);

let wallet = new ethers.Wallet.fromEncryptedJsonSync(
encryptedJson,
process.env.PRIVATE_KEY_PASSWORD,
);
wallet = await wallet.connect(provider);

const abiPath =
"/media/kalki/030ABB616FC574C0/visualstudio/learnBlockchain/simpleStorage_sol_SimpleStorage.abi";
const binaryPath =
"/media/kalki/030ABB616FC574C0/visualstudio/learnBlockchain/simpleStorage_sol_SimpleStorage.bin";
const abi = fs.readFileSync(abiPath, "utf8");
const binary = fs.readFileSync(binaryPath, "utf8");
const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
console.log("Deploying, please wait...");
const contract = await contractFactory.deploy();

const deploymentReceipt = await contract.deployTransaction.wait(1);
console.log(Contract deployed to ${contract.address});

let currentFavoriteNumber = await contract.retrieve();
console.log(Current Favorite NumbAer: ${currentFavoriteNumber});
console.log("Updating favorite number...");
let transactionResponse = await contract.store(7);
let transactionReceipt = await transactionResponse.wait(1);
currentFavoriteNumber = await contract.retrieve();
console.log(New Favorite Number: ${currentFavoriteNumber});
}

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

I am using alchemy for rpc url and my fake metamask account has 0.9593Sepolia ETH and 40 links

enter image description here

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.