mockOffChain.js
const { ethers, network } = require("hardhat")
async function mockKeepers() {
// const raffle = await ethers.getContractAt("Raffle")
const contractAddress = (await deployments.get("Raffle")).address
const raffle_contract = await ethers.getContractAt("Raffle", contractAddress)
const raffle = raffle_contract.address
const checkData = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(""))
const { upkeepNeeded } = await raffle.callStatic.checkUpkeep(checkData)
if (upkeepNeeded) {
const tx = await raffle.performUpkeep(checkData)
const txReceipt = await tx.wait(1)
const requestId = txReceipt.events[1].args.requestId
console.log(`Performed upkeep with RequestId: ${requestId}`)
if (network.config.chainId == 31337) {
await mockVrf(requestId, raffle)
}
} else {
console.log("No upkeep needed!")
}
}
async function mockVrf(requestId, raffle) {
console.log("We on a local network? Ok let's pretend...")
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
await vrfCoordinatorV2Mock.fulfillRandomWords(requestId, raffle.address)
console.log("Responded!")
const recentWinner = await raffle.getRecentWinner()
console.log(`The winner is: ${recentWinner}`)
}
mockKeepers()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
Error
yarn hardhat run scripts/mockOffChain.js --network localhost
yarn run v1.22.19
warning package.json: No license field
$ '/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/.bin/hardhat' run scripts/mockOffChain.js --network localhost
TypeError: Cannot read properties of undefined (reading 'checkUpkeep')
at mockKeepers (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/scripts/mockOffChain.js:49:54)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I don't understand how to resolve this error