TypeError: Cannot read properties of undefined (reading 'utils') #5571
Answered
by
alymurtazamemon
Bhavik-punmiya
asked this question in
Q&A
-
I am currently on Lesson 10 , earlier on lesson 9 when i tried to deploy the contract it ran well and contract even got verified. PS F:\HardHat Blockchain fcc\Hardhat-SmartContract-Lottery> hh node
Nothing to compile
Error HH604: Error running JSON-RPC server: ERROR processing skip func of F:\HardHat Blockchain fcc\Hardhat-SmartContract-Lottery\deploy\01-deploy-raffle.js:
TypeError: Cannot read properties of undefined (reading 'utils') utils/verify.jsconst { 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,
} 01-deploy-raffle.jsconst { network, ethers } = require("hardhat")
const {
networkConfig,
developmentChains,
VERIFICATION_BLOCK_CONFIRMATIONS,
} = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
const FUND_AMOUNT = ethers.utils.parseEther("1") // 1 Ether, or 1e18 (10^18) Wei
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let vrfCoordinatorV2Address, subscriptionId, vrfCoordinatorV2Mock
if (chainId == 31337) {
// create VRFV2 Subscription
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait()
subscriptionId = transactionReceipt.events[0].args.subId
// Fund the subscription
// Our mock makes it so we don't actually have to worry about sending fund
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT)
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
subscriptionId = networkConfig[chainId]["subscriptionId"]
}
const waitBlockConfirmations = developmentChains.includes(network.name)
? 1
: VERIFICATION_BLOCK_CONFIRMATIONS
log("----------------------------------------------------")
const arguments = [
vrfCoordinatorV2Address,
subscriptionId,
networkConfig[chainId]["gasLane"],
networkConfig[chainId]["keepersUpdateInterval"],
networkConfig[chainId]["raffleEntranceFee"],
networkConfig[chainId]["callbackGasLimit"],
]
const raffle = await deploy("Raffle", {
from: deployer,
args: arguments,
log: true,
waitConfirmations: waitBlockConfirmations,
})
// Ensure the Raffle contract is a valid consumer of the VRFCoordinatorV2Mock contract.
if (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
await vrfCoordinatorV2Mock.addConsumer(subscriptionId, raffle.address)
}
// Verify the deployment
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("Verifying...")
await verify(raffle.address, arguments)
}
log("Enter lottery with command:")
const networkName = network.name == "hardhat" ? "localhost" : network.name
log(`yarn hardhat run scripts/enterRaffle.js --network ${networkName}`)
log("----------------------------------------------------")
}
module.exports.tags = ["all", "raffle"] |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
May 30, 2023
Replies: 1 comment 11 replies
-
@Bhavik-punmiya Check your helper file, Are you using ethers there? If yes then make sure you import the ethers there. |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Bhavik-punmiya Yes, here I am saying that too!