"Cannot read properties of undefined" error #4985
Answered
by
alymurtazamemon
Mayank-Pandey1
asked this question in
Q&A
-
I get this error when I try to run the following command:
Here is my const { network } = require("hardhat");
const {
networkConfig,
developmentChains,
} = require("../helper-hardhat-config");
const { verify } = require("../utils/verify");
require("dotenv").config();
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments; //getting variables from deployments object
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
let ethUsdPriceFeedAddress;
if (developmentChains.includes(network.name)) {
const ethUsdAggregator = await deployments.get("MockV3Aggregator");
ethUsdPriceFeedAddress = ethUsdAggregator.address;
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
}
//when working with localhost or hardhat we will create a mock.
//Mocking is primarily used in unit testing. An object under test may have dependencies on other (complex) objects.
//To isolate the behaviour of the object you want to test you replace the other objects by mocks that simulate
//the behaviour of the real objects. This is useful if the real objects are impractical to incorporate into the
//unit test.
//In short, mocking is creating objects that simulate the behaviour of real objects.
const args = [ethUsdPriceFeedAddress];
const fundMe = await deploy("FundMe", {
from: deployer,
args: args, //put priceFeed Address here
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
});
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(fundMe.address, args);
}
};
module.exports.tags = ["all", "fundme"]; and below is my const networkConfig = {
5: {
name: "goerli",
ethUsdPriceFeed: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e",
},
11155111: {
name: "sepolia",
ethUsdPriceFeed: "0x694AA1769357215DE4FAC081bf1f309aDC325306",
},
1: {
name: "mainnet",
ethUsdPriceFeed: "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419",
},
};
const DECIMALS = 8;
const INITIAL_ANSWER = 200000000000;
const developmentChains = ["localhost", "hardhat"];
module.exports = {
networkConfig,
developmentChains,
DECIMALS,
INITIAL_ANSWER,
}; |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Mar 2, 2023
Replies: 2 comments 6 replies
-
@Mayank-Pandey1 console log the chainId before if-else statement and let me know the result. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
alymurtazamemon
-
In my case The button console isn't shown |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Mayank-Pandey1 console log the chainId before if-else statement and let me know the result.