VRFCoordinatorV2Mock is not defined?

304 Views Asked by At

Can anyone tell me why i might be getting the error "VRFCoordinatorV2Mock is not defined" when running hardhat deploy? It appears the error is in one of the two deploy scripts i am running. Both deploy scripts for this project pasted below. Probs not relevant but this is from this Chainlink tutorial... https://www.youtube.com/watch?v=xTnDTWHsbIs

Btw i have a folder called "test" in the contracts folder where i have imported the VRFCoordinatorV2Mock.sol contract and i have imported all the Chainlink contracts.

const { network } = require("hardhat")

module.exports = async function (hre) {
    const { getNamedAccounts, deployments } = hre
    const { deployer } = await getNamedAccounts()
    const { deploy, log } = deployments
    const chainId = network.config.chainId
    let vrfCoordinatorV2Address, subscriptionId
    const FUND_AMOUNT = "1000000000000000000"

    let tokenUris = [
        "ipfs://QmaVkBn2tKmjbhphU7eyztbvSQU5EXDdqRyXZtRhSGgJGo",
        "ipfs://QmZYmH5iDbD6v3U2ixoVAjioSzvWJszDzYdbeCLquGSpVm",
        "ipfs://QmYQC5aGZu2PTH8XzbJrbDnvhj3gVs7ya33H9mqUNvST3d",
    ]

    //if we are working on a testnet or mainnet the will the vrfCoordinatorV2Address exist? Yes it will
    //otherwise.... they won't! In which case we do mocking (set up fakeChainlink VFR node)
    if (chainId == 31337) {
        //make a fake chainlink VRF node
        const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
        vrfCoordinatorV2Address = VRFCoordinatorV2Mock.address
        const tx = await vrfCoordinatorV2Mock.createSubscription()
        const txReceipt = await tx.wait(1)
        subscriptionId = txReceipt.events[0].args.subscriptionId
        await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT)
    } else {
        //use the real ones
        vrfCoordinatorV2Address = "0x6168499c0cFfCaCD319c818142124B7A15E857ab"
        subscriptionId = "8898"
    }
    args = [
        vrfCoordinatorV2Address,
        "0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc",
        subscriptionId,
        "500000",
        //list of Dogs
        tokenUris,
    ]
    const randomIpfsNft = await deploy("RandomIpfsNft", {
        from: deployer,
        args: args,
        log: true,
    })
    console.log(randomIpfsNft.address)
}

THIS IS THE OTHER DEPLOY SCRIPTS FILE....

const BASE_FEE = "250000000000000000" // 0.25 is this the premium in LINK?
const GAS_PRICE_LINK = 1e9 // link per gas, is this the gas lane? // 0.000000001 LINK per gas

module.exports = async function (hre) {
    const { getNamedAccounts, deployments } = hre
    const { deployer } = await getNamedAccounts()
    const { deploy, log } = deployments
    const chainId = network.config.chainId

    if (chainId == 31337) {
        await deploy("VRFCoordinatorV2Mock", {
            from: deployer,
            log: true,
            args: [BASE_FEE, GAS_PRICE_LINK],
        })
    }
}
module.exports.tags = ["all", "mocks"]
1

There are 1 best solutions below

1
On

In the third line of your if statement:

vrfCoordinatorV2Address = VRFCoordinatorV2Mock.address

is should be:

vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address

as that is how it was stated in the line above.

Just going through the course myself, hopefully it helps anyone with the same issue.