Lesson 10: 99-update-frontend.js not updating when deploying to Rinkeby #794
-
Hello, Has anyone gotten 99-update-frontend.js to update the nextjs contractAddresses.json and abi.json when deploying to Rinkeby? I have tried my version & copy and pasted the version from the repository. The thing is that the await ethers.getContract doesn't appear to have returned with the raffle contract when deploying to Rinkeby. Deploying to localhost returns with a contract address. Notes: 1) Since I have already deployed the raffle contract in Lesson 9 to Rinkeby, hardhat knows that redeployment is not necessary. 2) I know that the environment variable UPDATE_FRONT_END is true because the "Writing to front end..." shows in the deployment output. hh deploy --network rinkeby
Nothing to compile
Files
-----
../nextjs-smartcontract-lottery/constants/abi.json ../nextjs-smartcontract-lottery/constants/contractAddresses.json
reusing "Raffle" at 0xDCa2D4ab0eb643B4d1138D8dd1629554f73c9F77
Verifying
Verifying contract...
Nothing to compile
Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
--> contracts/raffle.sol:84:7:
|
84 | bytes memory /* performData */
| ^^^^^^^^^^^^
Warning: Function state mutability can be restricted to view
--> contracts/raffle.sol:77:3:
|
77 | function checkUpkeep(
| ^ (Relevant source part starts here and spans across multiple lines).
Warning: Function state mutability can be restricted to pure
--> contracts/raffle.sol:169:3:
|
169 | function getNumWords() public view returns (uint256) {
| ^ (Relevant source part starts here and spans across multiple lines).
Already verified
Deploy raffle completed
--------------------------------------------
Writing to front end...
Front end written! I had the same problem with the version I wrote, so I wanted to see if the repository version made a difference. The below version was copied from the repository but with these minor updates:
const fs = require("fs");
const { network } = require("hardhat");
const frontEndContractsFile =
"../nextjs-smartcontract-lottery/constants/contractAddresses.json";
const frontEndAbiFile = "../nextjs-smartcontract-lottery/constants/abi.json";
console.log("Files\n-----\n", frontEndAbiFile, frontEndContractsFile);
module.exports = async () => {
if (process.env.UPDATE_FRONT_END) {
console.log("Writing to front end...");
updateContractAddresses();
updateAbi();
console.log("Front end written!");
}
};
async function updateAbi() {
const raffle = await ethers.getContract("Raffle");
fs.writeFileSync(
frontEndAbiFile,
raffle.interface.format(ethers.utils.FormatTypes.json)
);
}
async function updateContractAddresses() {
const raffle = await ethers.getContract("Raffle");
console.log("raffle.address\n------\n", raffle.address);
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));
}
module.exports.tags = ["all", "frontend"]; |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
-
Hi running to the same issue, tried add await before updateContractAddresses() and updateAbi(); it works. module.exports = async () => { |
Beta Was this translation helpful? Give feedback.
@PatrickAlphaC