-
Getting error in Lesson 9 Error: ERROR processing /root/hardhat-fcc/hardhat-smartcontract-lottery-fcc/deploy/01-deploy-raffle.js: TypeError: Cannot read properties of undefined (reading '0') Error occurring at line 23 My 01-deploy-raffle.js fileconst { network, ethers } = require("hardhat")
const { networkConfig, developmenChain } = require("../helper-hardhat-conifg")
const {verify} = require("../utils/verify")
const VRF_SUB_FUND_AMOUNT = ethers.parseEther("30")
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deployer } = await getNamedAccounts()
const { deploy, log } = deployments
const chainId = network.config.chainId
let vrfCoordinatorV2Address, subscriptionId
if (developmenChain.includes(network.name)) {
log("local network detected: deploying mocks....")
const VRF2CordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = VRF2CordinatorV2Mock.runner.address
// console.log(VRF2CordinatorV2Mock)
const transactionResponse = await VRF2CordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.events[0].args.subId
// Fund subscription
// Usually you had need the link token on a real network
// on local network -> fund the subscrition without link token
await VRF2CordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT)
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinator"]
subscriptionId = networkConfig[chainId]["subscriptionid"]
}
const entranceFee = networkConfig[chainId]["entranceFee"]
const gasLane = networkConfig[chainId]["gasLane"]
const gasLimit = networkConfig[chainId]["callbackGasLimit"]
const intervel = networkConfig[chainId]["intervel"]
const args = [vrfCoordinatorV2Address, entranceFee, gasLane, subscriptionId, gasLimit, intervel]
const raffle = await deploy("Raffle", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
if(!developmenChain.includes(network.name) && process.env.ETHERSCAN_API){
log("Verifying.....")
verify(raffle.address,args)
log("-----------------------------------------")
}
}
module.exports.tags = ["all","raffle"] I hardcoded the value of
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
Hi @coderharsx1122 I'm not sure why are you getting vrf address like this |
Beta Was this translation helpful? Give feedback.
@coderharsx1122
Ok I have figuered out what was the problem. First of all I highly recommend using ethers v5 instead of v6 as you do because of lack of understanding those are causing issues like yours...
In your
01-deploy-raffle.js
as I said you are getting contract address wrong way, which causing you this issue (ethers v6 error) you need to get it like below:instead of using some kind of
runner
or whatever.If you fix it you will get another error, which stands
InvalidConsumer()
to fix that add below to your script in same01-deploy-raffle.js
file: