Lesson7: SyntaxError: await is only valid in async functions and the top level bodies of modules #2374
-
in my if i comment out my verify function, it works just fine
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { network } = require("hardhat")
const { verify } = require("../utils/verify")
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
//const ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
let ethUsdPriceFeedAddress
if (chainId == 31337) {
ethUsdAggregator = await deployments.get("MockV3Aggregator")
ethUsdPriceFeedAddress = ethUsdAggregator.address
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["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}`)
log("---------------------------------------")
}
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(fundMe.address, [ethUsdPriceFeedAddress])
}
module.exports.tags = ["all", "fundme"] |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
const { run } = require("hardhat")
const verify = async (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.
-
@udayg24 It looks correct here! Can you show your console? or just push it to GitHub and leave a link here. |
Beta Was this translation helpful? Give feedback.
-
Hey @udayg24 move the if statement in your |
Beta Was this translation helpful? Give feedback.
Hey @udayg24 move the if statement in your
01-deploy-fundme.js
file into the enclosing}
of themodule.exports
section.