Lesson 9 : TypeError: Cannot read properties of undefined (reading 'length') #5600
-
this is the error when I try to run on 15:19;55, it show error "TypeError: Cannot read properties of undefined (reading 'length')"this is my code for 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("30");
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
let vrfCoordinatorV2Address;
let 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;
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", {
form: deployer,
args: args,
log: true,
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"]; My hardhat.config.js /** @type import('hardhat/config').HardhatUserConfig */
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 GOERLI_RPC_URL = process.env.GOERLI_RPC_URL;
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "key";
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "key";
module.exports = {
solidity: "0.8.8",
defaultNetwork: "hardhat",
network: {
hardhat: {
chainId: 31337,
blockConfirmations: 1,
},
sepolia: {
chainId: 11155111,
blockConfirmations: 6,
url: SEPOLIA_RPC_URL,
accounts: PRIVATE_KEY,
},
},
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
},
},
}; |
Beta Was this translation helpful? Give feedback.
Answered by
aaankeet
Jun 3, 2023
Replies: 1 comment 1 reply
-
@Alanle1011
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Alanle1011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Alanle1011
typo in your deploy.raffle.js