-
Error:
I can see that the mocks are being deployed to the local network, but not to the raffle, can someone help me out here? Deploy Code: const { network, ethers } = require("hardhat");
const {
developmentChains,
networkConfig,
} = require("../helper-hardhat-config");
const { verify } = require("../utils/verify");
const VRF_SUB_FUND_AMOUNT = ethers.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;
// Now that we have the subscription, we need to fund the subscription
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,
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"];
const { run } = require("hardhat");
const verify = async (contractAddress, args) => {
console.log("Verifying contract...");
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments: args,
});
} catch (err) {
if (err.message.toLowerCase().includes("already verified")) {
console.log("Already Verified!");
} else {
console.log(err);
}
}
};
module.exports = { verify }; |
Beta Was this translation helpful? Give feedback.
Answered by
kotysky
Oct 20, 2023
Replies: 1 comment 2 replies
-
I think your problem is here: subscriptionId = transactionReceipt.events[0].args.subId; and you are using Ethers 6, const filter = vrfCoordinatorV2Mock.filters.SubscriptionCreated
const events = await vrfCoordinatorV2Mock.queryFilter(filter, -1)
const event = events[0]
const args = event.args
subscriptionId = args.subId |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think your problem is here:
and you are using Ethers 6,
if you want use that code,I guess you need downgrade de Ethers 6 to 5, but if you want use Ethers 6, like me, please, try the code below. It works for me.