Lesson 9: TypeError: ethers.getContract is not a function #523
-
I keep getting this error message when trying to deploy my Fund Me contract: const { ethers } = require("ethers")
const { network } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
const VAF_SUB_FUND_AMOUNT = ethers.utils.parseEther("2")
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let vrfCoordinatorV2Address, subscriptionId
if (chainId == 31337) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.events[0].subId
//Fund the subscription
//Ususally, you'd neeed the link token on a real network
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VAF_SUB_FUND_AMOUNT)
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
subcriptionId = 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: networks.config.blockConfirmations || 1,
})
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("Verifying...")
await verify(raffle.address, args)
}
log("---------------------------------------------------")
}
module.exports.tags = ["all", "raffle" ] |
Beta Was this translation helpful? Give feedback.
Answered by
gonzales17
Jun 23, 2022
Replies: 1 comment 1 reply
-
"ethers" should come from "hardhat". So remove this line:
And modify the line below it to read:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
su-adam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"ethers" should come from "hardhat". So remove this line:
const { ethers } = require("ethers")
And modify the line below it to read:
const { network, ethers } = require("hardhat")