Lesson 9: TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') #5026
-
I'm on Lesson 9: Hardhat Smart Contract Lottery. 15:20:03 on youtube. Gave this error :
00-deploy-mocks.js: const { ethers } = require("hardhat")
const { developmentChains } = require("../helper-hardhat-config")
const BASE_FEE = ethers.utils.parseEther("0.25") // 0.25 is the premium . it costs 0.25 LINK per request
const GAS_PRICE_LINK = 1e9 // calculated value based on the gas price of the chain
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const args = [BASE_FEE, GAS_PRICE_LINK]
if (developmentChains.includes(network.name)) {
log("Local network detected! Deploying mocks...")
// deploy a mock vrfcoordinator
await deploy("VRFCoordinatorV2Mock", {
from: deployer,
log: true,
args: args,
})
log("Mocks Deployed! ")
log("_______________________")
}
}
module.exports.tags = ["all", "mocks"] 01-deploy-raffle.js: const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../helper-hardhat-config")
const VRF_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 (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.events[0].args.subId
// Fund the subscription
// usually, you'd need the link token on a real network
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,
waitConfirmations: network.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"] helper-hardhat-config.js: const { network, ethers } = require("hardhat")
networkConfig = {
5: {
name: "goerli",
vrfCoordinatorV2: "0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D",
etntranceFee: ethers.utils.parseETher("0.01"),
gasLane: "0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15",
subscriptionId: "0",
callbackGasLimit: "500000",
interval: "30",
},
31337: {
name: "hardhat",
etntranceFee: ethers.utils.parseETher("0.01"),
gasLane: "0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15",
callbackGasLimit: "500000",
},
}
const developmentChains = ["hardhat", "localhost"]
module.exports = {
networkConfig,
developmentChains,
} |
Beta Was this translation helpful? Give feedback.
Answered by
paulcoffee85
Mar 7, 2023
Replies: 2 comments
-
There's a few things. for now , You'll also need to add a few lines of code to involve updates.
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Also, change version of ethers. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
arifulone
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, change version of ethers.
#4924 (comment)