0
const { network, ethers } = require("hardhat")
const { developmentChain } = require("../helper-hardhat-config")
const { networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")

const VRF_SUB_FUND_AMOUNT = ethers.utils.parseEther("50")
module.exports = async function ({ getNamedAccounts, deployments }) {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId
    let vrfCoordinatorV2Address, subscriptionId

    if (/*developmentChain.includes(network.name)*/ chainId == 31337) {
        const vrfCoordinatorV2Mock = await deployments.get("VRFCoordinatorV2Mock")
        vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
        //creation of subscription id and funding it for local testing
        const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
        const transactionReceipt = await transactionResponse.wait(1)
        subscriptionId = transactionReceipt.events[0].args.subId
        //fund the subscription
        //on real testnet we need LINK
        await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT)
    } else {
        vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
        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.blockConfirmation || 1,
    })

    if (
        /*!developmentChain.includes(network.name)*/ !chainId == 31337 &&
        process.env.ETHERSCAN_API_KEY
    ) {
        log("Veryfying on etherscan...")
        await verify(raffle.address, args)
    }
    log("--------------------------------------------------")
}

module.exports.tags = ["all", "raffle"]

An unexpected error occurred:

yarn hardhat deploy
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' deploy
Nothing to compile
Local network detected! Deploying Mocks....
deploying "VRFCoordinatorV2Mock" (tx: 0x7a943804391704783ffc0b6311b856826b2463755365e0d92fd92bd9a39afe3b)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 2971793 gas
Mocks Deployed!
--------------------------------------------------
An unexpected error occurred:

Error: ERROR processing /home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/deploy/01-deploy-raffle.js:
TypeError: vrfCoordinatorV2Mock.createSubscription is not a function
    at Object.module.exports [as func] (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/deploy/01-deploy-raffle.js:17:64)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at listOnTimeout (node:internal/timers:538:9)
    at processTimers (node:internal/timers:512:7)
    at DeploymentsManager.executeDeployScripts (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1211:22)
    at DeploymentsManager.runDeploy (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1060:5)
    at SimpleTaskDefinition.action (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat-deploy/src/index.ts:450:5)
    at Environment._runTaskDefinition (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat/src/internal/core/runtime-environment.ts:358:14)
    at Environment.run (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat/src/internal/core/runtime-environment.ts:191:14)
    at DeploymentsManager.executeDeployScripts (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1214:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at listOnTimeout (node:internal/timers:538:9)
    at processTimers (node:internal/timers:512:7)
    at DeploymentsManager.runDeploy (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1060:5)
    at SimpleTaskDefinition.action (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat-deploy/src/index.ts:450:5)
    at Environment._runTaskDefinition (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat/src/internal/core/runtime-environment.ts:358:14)
    at Environment.run (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat/src/internal/core/runtime-environment.ts:191:14)
    at SimpleTaskDefinition.action (/home/rajvir_singh/FCC Full stack Web3 course/Hardhat Lottery L9/node_modules/hardhat-deploy/src/index.ts:601:32)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Can someone help me out with this.. I am having no idea what mistake I am making.

3 Answers 3

0
TypeError: vrfCoordinatorV2Mock.createSubscription is not a function

This error means that there isn't a function called createSubscription in the vrfCoordinatorV2Mock contract that you're pulling out of the deployments being passed into the function. You'll need to check the contract code being passed into the function.

There may be additional issues here - you have the script call a fundSubscription function, but do not clearly fund the caller with the funds with which to fund the subscription nor grant approvals to the contract, for example. This might not be an issue - you may be using a separate script for this, or may have made the mock function such that it doesn't actually transfer any funds.

As an aside, this seems to be a script for working through Patrick Collins's course. A useful trick when working through tutorials like this can be searching GitHub for how other people solved it, just be careful not to let that stop you from learning how to do things on your own.

Hope this helps!

0

You just need to use getContract instead of get...

use this... const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer);

instead of this... const vrfCoordinatorV2Mock = await deployments.get("VRFCoordinatorV2Mock")

0
const signer = await ethers.getSigner(deployer);
const VRFCoordinatorV2_5Deplomewnt = await deployments.get("VRFCoordinatorV2_5Mock")
VRFCoordinatorV2_5Address = VRFCoordinatorV2_5Deplomewnt.address
const VRFCoordinatorV2_5=await ethers.getContractAt("VRFCoordinatorV2_5Mock",VRFCoordinatorV2_5Address,signer)

Use the above syntax if you are using deployment.get because it retreives the contract information but doesn't associate it with a signer, but ethers.getContract retrieves the contract information and associates it with a signer that is deployer in one step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.