Lesson 7 : Error: ERROR processing /root/hh-fcc/hardhat-fund-me-fcc/deploy/01-deploy-fund-me.js: TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed') #5727
Answered
by
alymurtazamemon
MrPositive0709
asked this question in
Q&A
-
this is my 01-deploy-fund-me.js file : const { network } = require("hardhat");
const { networkConfig, developmentChain } = require("../helper-hardhat-config");
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
console.log(chainId);
//If chainId is X use address Y
let ethUsdPriceFeedAddress;
if (developmentChain.includes(network.name)) {
const ethUsdAggregator = await deployments.get("MockV3Aggregator");
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
}
//If the contract doesn't exist , we deploy a minimum version for our local testing
// when going for localhost or hardhat network we want to use a mock
const fundMe = await deploy("FundMe", {
from: deployer,
args: [ethUsdPriceFeedAddress], // put price feed address
log: true,
});
log("-------------------------------------");
};
module.exports.tags = ["all", "fundme"]; this is my hardhat-config.js file : require("dotenv").config();
require("@nomiclabs/hardhat-etherscan");
require("@nomiclabs/hardhat-waffle");
require("hardhat-gas-reporter");
require("solidity-coverage");
require("hardhat-deploy");
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "";
const SEPOLIA_RPC_URL =
process.env.SEPOLIA_RPC_URL ||
"https://eth-sepolia.g.alchemy.com/v2/YOUR-API-KEY";
const PRIVATE_KEY =
process.env.PRIVATE_KEY ||
"0x11ee3108a03081fe260ecdc106554d09d9d1209bcafd46942b10e02943effc4a";
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "";
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
defaultNetwork: "hardhat",
solidity: "0.8.18",
networks: {
hardhat: {
chainId: 31337,
// gasPrice: 130000000000,
},
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
blockConfirmations: 6,
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
currency: "USD",
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
},
},
}; and this is helper-hardhat-config.js : const networkConfig = {
11155111: {
name: "sepolia",
ethUsdPriceFeed: "0x694AA1769357215DE4FAC081bf1f309aDC325306",
},
};
const developmentChain = ["hardhat", "localhost"];
const DECIMALS = 8;
const INITIAL_ANSWER = 200000000000;
module.exports = {
networkConfig,
developmentChain,
DECIMALS,
INITIAL_ANSWER,
}; after deploy the 01-deploy-fund-me.js it returns me this bug : Error: ERROR processing /root/hh-fcc/hardhat-fund-me-fcc/deploy/01-deploy-fund-me.js:
TypeError: Cannot read properties of undefined (reading 'ethUsdPriceFeed') |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Jun 23, 2023
Replies: 1 comment 1 reply
-
@MrPositive0709 Because the code is not able to read let ethUsdPriceFeedAddress
if (chainId == 31337) {
const ethUsdAggregator = await deployments.get("MockV3Aggregator")
ethUsdPriceFeedAddress = ethUsdAggregator.address
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
} If the user deploying on local host then take the address from mocks otherwise from the |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MrPositive0709
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MrPositive0709 Because the code is not able to read
ethUsdPriceFeed
because it is not defined for localhost in config file, you are missing this logic.If the user deploying on local host then take the address from mocks otherwise from the
networkConfig