Lesson 10: Error: ENOENT: no such file or directory, open '../../nextjs-smartcontract-lottery-fcc/constants/contractAddresses.json' #4662
Answered
by
alymurtazamemon
umairahmed88
asked this question in
Q&A
-
My code is const { ethers, network } = require("hardhat");
const fs = require("fs");
const FRONT_END_ADDRESSES_FILE =
"../../nextjs-smartcontract-lottery-fcc/constants/contractAddresses.json";
const FRONT_END_ABI_FILE =
"../../nextjs-smartcontract-lottery-fcc/constants/abi.json";
module.exports = async function () {
if (process.env.UPDATE_FRONT_END) {
console.log("Updating front end...");
updateContractAddresses();
updateAbi();
}
};
async function updateAbi() {
const raffle = await ethers.getContract("Raffle");
fs.writeFile(
FRONT_END_ABI_FILE,
raffle.interface.format(ethers.utils.FormatTypes.json)
);
}
async function updateContractAddresses() {
const raffle = await ethers.getContract("Raffle");
const chainId = network.config.chainId.toString();
const currentAddresses = JSON.parse(
fs.readFileSync(FRONT_END_ADDRESSES_FILE, "utf-8")
);
if (chainId in contractAddresses) {
if (!contractAddresses[chainId].includes(network.address)) {
contractAddresses[chainId].push(raffle.address);
}
}
{
currentAddresses[chainId] = [raffle.address];
}
fs.writeFileSync(FRONT_END_ADDRESSES_FILE, JSON.stringify(currentAddresses));
}
module.exports.tags = ["all", "frontend"]; I have tried both const FRONT_END_ADDRESSES_FILE =
"../../nextjs-smartcontract-lottery-fcc/constants/contractAddresses.json";
const FRONT_END_ABI_FILE =
"../../nextjs-smartcontract-lottery-fcc/constants/abi.json"; and this const FRONT_END_ADDRESSES_FILE =
"../nextjs-smartcontract-lottery-fcc/constants/contractAddresses.json";
const FRONT_END_ABI_FILE =
"../nextjs-smartcontract-lottery-fcc/constants/abi.json"; I got this error Error: ENOENT: no such file or directory, open '../../nextjs-smartcontract-lottery-fcc/constants/contractAddresses.json |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Jan 31, 2023
Replies: 1 comment 1 reply
-
@umairahmed88 First of all make sure in your frontend project folder at the root level you should have a folder named In addition to this, you should make sure your blockchain code project and frontend code project are inside the same folder and then you are using the paths accordingly. If you are sure you have done all of these, then show me your folders structure. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
umairahmed88
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@umairahmed88 First of all make sure in your frontend project folder at the root level you should have a folder named
constants
and inside it, you should have these filescontractAddresses.json
andabi.json
.In addition to this, you should make sure your blockchain code project and frontend code project are inside the same folder and then you are using the paths accordingly.
If you are sure you have done all of these, then show me your folders structure.