-
When I run yarn hardhat node, my contractAddresses.json and abi.json file doesn't update. I'm not able to figure out where is the mistake as there are no errors while running. Time-stamp: 17:36:05 99-deploy-frontEnd.js: const { ethers, network } = require("hardhat");
const fs = require("fs");
const FRONT_END_ADDRESSES_FILE =
"../../nextjs-smartcontract-lottery/constants/contractAddresses.json";
const FRONT_END_ABI_FILE =
"../../nextjs-smartcontract-lottery/constants/abi.json";
module.exports = async function () {
if (process.env.UPDATE_FRONT_END) {
console.log("Updating front end...");
await updateContractAddresses();
await updateAbi();
console.log("Front end Updated!");
}
};
async function updateAbi() {
const raffle = await ethers.getContract("Raffle");
fs.writeFileSync(
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 currentAddress = JSON.parse(
fs.readFileSync(FRONT_END_ADDRESSES_FILE, "utf8")
);
if (chainId in currentAddress) {
if (!currentAddress[chainId].includes(raffle.address)) {
currentAddress[chainId].push(raffle.address);
}
} else {
currentAddress[chainId] = [raffle.address];
}
fs.writeFileSync(FRONT_END_ADDRESSES_FILE, JSON.stringify(currentAddress));
}
module.exports.tags = ["all", "frontend"]; |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
I would recommend following along w/ Patrick properly. |
Beta Was this translation helpful? Give feedback.
-
You code looks alright, did you check the path of directory? if nextjs-smartcontract-lottery and your hardhat lottery code under same directory, it should be only one ../ like this: const FRONT_END_ADDRESSES_FILE = or you need to check what is the correct path format for windows, because the tutorial code example is under MAC. also make sure the process.env.UPDATE_FRONT_END = true |
Beta Was this translation helpful? Give feedback.
You code looks alright, did you check the path of directory? if nextjs-smartcontract-lottery and your hardhat lottery code under same directory, it should be only one ../ like this:
const FRONT_END_ADDRESSES_FILE =
"../nextjs-smartcontract-lottery/constants/contractAddresses.json";
const FRONT_END_ABI_FILE =
"../nextjs-smartcontract-lottery/constants/abi.json";
or you need to check what is the correct path format for windows, because the tutorial code example is under MAC.
also make sure the process.env.UPDATE_FRONT_END = true