Lesson 9 : Raffle deploy error. #2758
-
I go to test the deploy scripts and my mocks deploy fine however there is an issue with the raffle code deploying. Attempted to diagnose it but remain unsure. Deploy script code: const { network } = require("hardhat");
const {
developmentChains,
networkConfig,
} = require("../helper-hardhat-config");
const { verify } = require("../helper-hardhat-config");
const VRF_SUB_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, subsriptionId, vrfCoordinatorV2Mock;
if (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract(
"VRFCoordinatorV2Mock"
);
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address;
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription();
const transactionReciept = await transactionResponse.wait(1);
subsriptionId = transactionReciept.events[0].args.subId;
log("Subscription created successfully");
// Subscription now exists via contract. Now need to fund the subscription
// Mainnets need link token to fund SUB
await vrfCoordinatorV2Mock.fundSubscription(subsriptionId, VRF_SUB_AMOUNT);
log("Successfully Funded Subscription");
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"];
subsriptionId = 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,
subsriptionId,
callbackGasLimit,
interval,
];
const raffle = await deploy("Raffle", {
from: deployer,
args: args,
log: true,
waitConfirmations: 1,
});
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
log("Verifying Contract Source Code...");
await verify(raffle.address, args);
}
log("------------------------------------");
log("Contract Deployed and Verified Successfully!");
};
module.exports.tags = ["all", `"raffle"];` And the error code is as follows: An unexpected error occurred:
Error: ERROR processing /Users/c/Desktop/Hard-Hat-Learning/hardhat-smartcontract-lottery/deploy/01-deploy-raffle.js:
TypeError: Cannot read properties of undefined (reading 'undefined')
at Object.module.exports [as func] (/Users/c/Desktop/Hard-Hat-Learning/hardhat-smartcontract-lottery/deploy/01-deploy-raffle.js:34:36) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Push to GitHub please |
Beta Was this translation helpful? Give feedback.
-
@Cronk123 How are you verifying your script? Do you have the a folder named utils where you have created a file named verify.js? Because I see your are importing verify from helper.config. Also you have declared
this, in my opinion is not the best practice. Also I see backticks here |
Beta Was this translation helpful? Give feedback.
-
Hey @Cronk123 First of all, there is a problem on line 13. Remove the |
Beta Was this translation helpful? Give feedback.
Hey @Cronk123 First of all, there is a problem on line 13. Remove the
{}
on chainId. The lineconst { chainId } =network.config.chainId;
should beconst chainId = network.config.chainId;
I see the problem is coming from line 34. Make sure the
entranceFee
value is fetched correctly from yourhelper-hardhat-config.js
If you feel it is okay, share a link to your github repo we'll help you look into it.Another thing, you are fetching your
verify
function fromhelper-hardhat-config
from sheer memory I'm guessing it should be in../util/verify
instead. Just check if you are fetching it correctly.Third, as @ashrth has pointed out above, remove the backticks (``) in this line ["all",
"raffle"];