Lesson 10. Problem with front-end automation #5106
-
Hi, in the lesson Patric showed us how to make a deploy file that automatically updates the abi and the contractAdresses file on the front end. It first worked fine, but then I ran into a problem and formated those two files to start fresh from the start. Then the problem occurred: Only the abi file was written automatically after deployment. I tried to fix the file, but only ended up it not being able to even update the abi file automatically. Here is my deploy script: const { ethers } = require("hardhat")
const fs = require("fs")
const FRONT_END_ADDRESSES_FILE = "../next-js-sc-lottery/constants/coads.json"
const FRONT_END_ABI_FILE = "../next-js-sc-lottery/constants/abi.json"
module.exports = async function () {
if (process.env.UPDATE_FRONT_END) {
console.log("Updating front end...")
updateContractAddresses()
updateAbi()
console.log("front end updated")
}
}
async function updateAbi() {
const lottery = await ethers.getContract("Lottery")
fs.writeFileSync(FRONT_END_ABI_FILE, lottery.interface.format(ethers.utils.FormatTypes.json))
}
async function updateContractAddresses(network) {
const lottery = await ethers.getContract("Lottery")
const coads = JSON.parse(fs.readFileSync(FRONT_END_ADDRESSES_FILE, "utf-8"))
const chainId = network.config.chainId.toString()
if (chainId in coads) {
if (!coads[chainId].includes(lottery.address)) {
coads[chainId].push(lottery.address)
}
} else {
coads[chainId] = [lottery.address]
}
fs.writeFileSync(FRONT_END_ADDRESSES_FILE, JSON.stringify(coads))
}
module.exports.tags = ["all", "frontend"] and here is a link to my front-end repo: Help is much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
@Sosiaalinen Everything looks perfect only here If you leave your backend repo link as well then I can test it locally. |
Beta Was this translation helpful? Give feedback.
@Sosiaalinen Everything looks perfect only here
async function updateContractAddresses(network)
you have added thenetwork
parameter but you are now passing any parameter while calling may be due to that it gets failed.If you leave your backend repo link as well then I can test it locally.