TypeError: vrfCoordinatorV2Mock.createSubsctiption is not a function #2216
-
const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat.config")
const { verify } = require("../helper-hardhat.config")
const FUND_AMOUNT = "100000000000000000" //ethers.utils.parseEther("2")
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let vrfCoordinatorV2Address, subsciptionId
if (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await deployments.get("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubsctiption()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.events[0].args.subId
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT)
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
const subscriptionId = networkConfig[chainId]["subscriptionId"]
}
const entranceFee = networkConfig[chainId]["entranceFee"]
const gasLane = networkConfig[chainId]["gasLane"]
const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"]
const interval = networkConfig[chainId]["interval"]
const args = [
vrfCoordinatorV2Address,
entranceFee,
gasLane,
subscriptionId,
callbackGasLimit,
interval,
]
const raffle = await deploy("Raffle", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfitmations || 1,
})
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("-------Verifying.... Please Wait !-------------")
await verify(raffle.address, args)
}
log("--------------------------------------------------------------------------------")
}
module.exports.tags = ["all", "raffle"]` Ok so i am getting error "TypeError: vrfCoordinatorV2Mock.createSubsctiption is not a function" with the code above. Now I had to make some adjustment as in the previous lesson we used
the "getContract" piece is giving me this error: So I am stuck now, I had searched the discussions for "getContract" error, I think nobody got this error so I had to change the code, may be I am missing some "imports" as I cant use command "ethers.utils.parseEther" as well. That thing is generating another error "TypeError: Cannot read properties of undefined (reading 'utils')". Please Help me out I am stuck and have no clue whats going on |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 24 replies
-
Hey @mmuaaz there is a typo in your code. You've written |
Beta Was this translation helpful? Give feedback.
-
@mmuaaz Replace these: - const vrfCoordinatorV2Mock = await deployments.get("VRFCoordinatorV2Mock")
+ const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock"); - const transactionResponse = await vrfCoordinatorV2Mock.createSubsctiption()
+ const transactionResponse = await vrfCoordinatorV2Mock.createSubscription(); |
Beta Was this translation helpful? Give feedback.
-
I made a PR, merge it and let me know if that fixes it. |
Beta Was this translation helpful? Give feedback.
-
@alymurtazamemon the solution with the following fix worked for me
But I don't get why the deployments.get doesn't work. It works fine for the FundMe contract. Will you please explain? |
Beta Was this translation helpful? Give feedback.
@mmuaaz Replace these: