Lesson 7: TypeError: Cannot read property 'ethUsdPriceFeed' of undefined #333
-
The contracts deploy with no issue when using local hose, however error arises when deploying to Rinkeby network const { getNamedAccounts, deployments, network } = require("hardhat")
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
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"]
}
log("----------------------------------------------------")
log("Deploying FundMe and waiting for confirmations...")
// log(ethUsdPriceFeed)
const fundMe = await deploy("FundMe", {
from: deployer,
args: [ethUsdPriceFeedAddress],
log: true,
// we need to wait if on a live network so we can verify properly
waitConfirmations: network.config.blockConfirmations || 1,
})
log(`FundMe deployed at ${fundMe.address}`)
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(fundMe.address, args) //args
}
}
module.exports.tags = ["all", "fundme"] Verify contract const { run } = require("hardhat")
async function verify (contractAddress, args) {
console.log("Verifying contract...")
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments: args,
})
} catch (e) {
if (e.message.toLowerCase().includes("already verified")) {
console.log("Already verified!")
} else {
console.log(e)
}
}
}
module.exports = { verify } |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@su-adam If you are talking about deploy-mocks.js, below are a few observations comparing your script with mine. From here it seems you have several issues: | | | Also, have you imported the right networkConfig data for your networks in helper-hardhat-config.js? |
Beta Was this translation helpful? Give feedback.
-
I copied your deploy.js and it was running successfully. Could you please share your
|
Beta Was this translation helpful? Give feedback.
@su-adam If you are talking about deploy-mocks.js, below are a few observations comparing your script with mine.
From here it seems you have several issues:
|
const { getNamedAccounts, deployments, network } = require("hardhat")
You don't need: getNamedAccounts, deployments
|
const args = [ethUsdPriceFeedAddress];
missing before const fundMe, this define the args parameter in const fundMe
|
args: args
instead ofargs: [ethUsdPriceFeedAddress]
|
log(`FundMe deployed at ${fundMe.address}`)
Not sure why you have this line
Also, have you imported the right networkConfig data for your networks in helper-hardhat-config.js?
| pricefeed
| chainId