Lesson 9: ReferenceError: networks is not defined #1228
-
When deploying Raffle.sol contract, Mocks deployed but Deploy-raffle.js returned this error Error: ERROR processing C:\Users\PC\Desktop\DEVELOPEMENT\hardhat-smartcontract-lottery-fcc\deploy\01-deploy-raffle.js: 01-deploy-raffle.js const { network, getNamedAccounts, deployments, run } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../helper-hardhat-config")
const VRF_FUND_AMOUNT = ethers.utils.parseEther("30")
module.exports = async function ({getNamedAccounts, deployments}){
const { deploy, log } = deployments
const {deployer} = await getNamedAccounts()
const chainId = network.config.chainId
//chainId of vrfco-ordinator
let vrfCoordinatorV2Address
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 sunscription
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_FUND_AMOUNT)
//if we are not on a local network
//vrfCoordinator will be derived from networkconfig
//in helper-hardhat-config
//import the networkConfig
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
subscriptionId = networkConfig[chainId]["subscription"]
}
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,
//from args[], pass contructor contracts into it
//create a Helpers config()
})
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY){
log("Verifying......")
await verify(raffle.address, args)
}
log("...........................")
}
module.exports.tags = ["all", "raffle"]
hardhat.config.js require("@nomiclabs/hardhat-waffle")
require("@nomiclabs/hardhat-etherscan")
require("hardhat-deploy")
require("solidity-coverage")
require("hardhat-gas-reporter")
require("hardhat-contract-sizer")
require("dotenv").config()
const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
module.exports = {
defaultNetwork:"hardhat",
networks: {
hardhat: {
chainId: 31337,
blockConfirmations: 1,
},
rinkeby: {
chainId: 4,
blockConfirmations: 6,
url:RINKEBY_RPC_URL,
accounts: [PRIVATE_KEY]
}
},
solidity: "0.8.7",
namedAccounts:{
deployer: {
default: 0,
},
player: {
default: 1,
},
},
} helper-hardhat-config.js const { ethers } = require("hardhat")
const networkConfig = {
4: {
name: "rinkeby",
vrfCoordinatorV2: "0x6168499c0cFfCaCD319c818142124B7A15E857ab",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0xd4bb89654db74673a187bd804519e65e3f71a52bc55f11da7601a13dcf505314",
subscriptionId: "0",
callbackGasLimit: "500000", //500,000
interval: "30",
},
31337: {
name: "hardhat",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0xd4bb89654db74673a187bd804519e65e3f71a52bc55f11da7601a13dcf505314",
},
//add development chains for mocks
}
const developmentChains = ["hardhat", "localhost"]
module.exports = {
networkConfig,
developmentChains,
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@Maakai123 Please follow this guide next time you ask a question. How to Ask Question Guide - waitConfirmations: networks.config.blockConfirmations || 1,
+ waitConfirmations: network.config.blockConfirmations || 1, |
Beta Was this translation helpful? Give feedback.
-
The problem lies here:
instead, it should be:
If this fixes it, mark Ali's as it was before mine. |
Beta Was this translation helpful? Give feedback.
@Maakai123 Please follow this guide next time you ask a question. How to Ask Question Guide