-
Hi, I was going through lesson 10: NextJS Smart Contract Lottery where we wrote the script to update the nextjs folder with the abi and the contract address of the deployed contracts. However, this update only happens when I run If I deploy on any network, like rinkeby with It says "Front end written" but doesnt write anything and the files are blank (both abi and address) On running it through the debugger, I see that the code drops out of the function Function for reference: async function updateContractAddresses() {
const raffle = await ethers.getContract("Raffle")
const contractAddresses = JSON.parse(fs.readFileSync(frontEndContractsFile, "utf8"))
if (network.config.chainId.toString() in contractAddresses) {
if (!contractAddresses[network.config.chainId.toString()].includes(raffle.address)) {
contractAddresses[network.config.chainId.toString()].push(raffle.address)
}
} else {
contractAddresses[network.config.chainId.toString()] = [raffle.address]
}
fs.writeFileSync(frontEndContractsFile, JSON.stringify(contractAddresses))
} Ran this on a fresh clone from the repo, so the issue exists in its current state. Way to replicate:
How do we copy over address/abi from testnet/mainnet deployments? Update: and then I get the correct address. For some reason, the contract cannot be retrieved in the script, but can be retrieved in the console? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Had the same problem. I have added
Let me know if this is wrong or bad coding practice (so I can run it differently). But it works. |
Beta Was this translation helpful? Give feedback.
Had the same problem. I have added
await
statements like so and it updated:Let me know if this is wrong or bad coding practice (so I can run it differently). But it works.