Dont know sever is syncing with another blockchain
I humbly told you that when try to deploy this file
const {
frontEndContractsFile,
frontEndAbiLocation,
} = require("../helper-hardhat-config");
require("dotenv").config();
const fs = require("fs");
const { network, ethers } = require("hardhat");
module.exports = async () => {
if (process.env.UPDATE_FRONT_END) {
console.log("Writing to front end...");
await updateContractAddresses();
await updateAbi();
console.log("Front end written!");
}
};
async function updateAbi() {
const nftMarketplace = await ethers.getContract("NftMarketplace");
const basicNft = await ethers.getContract("BasicNft");
fs.writeFileSync(
`${frontEndAbiLocation}NftMarketplace.json`,
//do formate the nftMarkeplace contracts interface/abi code into ethers.utils.FormatTypes.json format
nftMarketplace.interface.format(ethers.utils.FormatTypes.json)
);
fs.writeFileSync(
`${frontEndAbiLocation}BasicNft.json`,
basicNft.interface.format(ethers.utils.FormatTypes.json)
);
}
async function updateContractAddresses() {
const chainId = network.config.chainId.toString();
const nftMarketplace = await ethers.getContract("NftMarketplace");
const contractAddresses = JSON.parse(
fs.readFileSync(frontEndContractsFile, "utf8")
);
if (chainId in contractAddresses) {
if (
!contractAddresses[chainId]["NftMarketplace"].includes(
nftMarketplace.address
)
) {
contractAddresses[chainId]["NftMarketplace"].push(nftMarketplace.address);
}
} else {
contractAddresses[chainId] = { NftMarketplace: [nftMarketplace.address] };
}
fs.writeFileSync(frontEndContractsFile, JSON.stringify(contractAddresses));
}
module.exports.tags = ["all", "frontend"];
using this command yarn hardhat deploy --network localhost --tags frontend
its gives me an error
Error: ERROR processing /Users/apple/Documents/Projects/blockchain/hardhat-nft-marketplace-backend/deploy/03-update-front-end.js:
TypeError: Cannot read properties of undefined (reading 'toString')
at updateContractAddresses (/Users/apple/Documents/Projects/blockchain/hardhat-nft-marketplace-backend/deploy/03-update-front-end.js:33:42)
at Object.module.exports [as func] (/Users/apple/Documents/Projects/blockchain/hardhat-nft-marketplace-backend/deploy/03-update-front-end.js:12:11)
at DeploymentsManager.executeDeployScripts (/Users/apple/Documents/Projects/blockchain/hardhat-nft-marketplace-backend/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1220:41)
at DeploymentsManager.runDeploy (/Users/apple/Documents/Projects/blockchain/hardhat-nft-marketplace-backend/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1053:16)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
but with “yarn hardhat deploy” command it works fine and deployed the stuff
Now dont know it deployed where and using what blockchain but the chaindId says its localhost 31337
I am happy that you are helping @cryptokid