-
Notifications
You must be signed in to change notification settings - Fork 3.3k
LESSON 9 => TypeError: Cannot read properties of undefined (reading '0') #5779
-
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.getAddress const transactionResposne = await vrfCoordinatorV2Mock.createSubscription() const transactionReceipt = await transactionResposne.wait(1) subscriptionId = transactionReceipt.events[0].args.subId // we have to fund the subsciption 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"] 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) { console.log("Verifying") await verify(raffle.address, args) } } module.exports.tags = ["all","raffle"]
This is my deploy code for raffle. Probably the error is in this line.
subscriptionId = transactionReceipt.events[0].args.subId
Beta Was this translation helpful? Give feedback.
All reactions
@harry2855 No this is not an ethers issue, instead the mock contract response was not emitting the event of subscript created. But we can by pass it because we know it is the first subscript so we can do this
- subscriptionId = transactionReceipt.events[0].args.subId + subscriptionId = 1
And also address is know renamed to target vrfCoordinatorV2Address = vrfCoordinatorV2Mock.target;
Replies: 2 comments 20 replies
-
@harry2855 You can console log the transactionReceipt and see if there is any event or not, because it is saying undefined.
Beta Was this translation helpful? Give feedback.
All reactions
-
@harry2855 Please leave your repository link so I can test it.
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Hey @alymurtazamemon , I rolled back to ether v5 but now I am getting following error
TypeError: (0 , ethers_1.getAddress) is not a function
I have commited changes in the repo.
Beta Was this translation helpful? Give feedback.
All reactions
-
@harry2855 No this is not an ethers issue, instead the mock contract response was not emitting the event of subscript created. But we can by pass it because we know it is the first subscript so we can do this
- subscriptionId = transactionReceipt.events[0].args.subId + subscriptionId = 1
And also address is know renamed to target vrfCoordinatorV2Address = vrfCoordinatorV2Mock.target;
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 4 -
❤️ 3
-
I have rolled back to the previous version now and now running into another error. You can check in the thread.
Beta Was this translation helpful? Give feedback.
All reactions
-
Try this version of Ethers. I had almost a similar problem. This solved it.
yarn add ethers@5.7.2
Beta Was this translation helpful? Give feedback.
All reactions
-
👎 4
-
Rolling back to previous versions of ethers shouldn't be the marked answer guys.
Beta Was this translation helpful? Give feedback.
All reactions
-
now in latest version of ethers can someone say how to log the events from transaction receipt ., because in the txn receipt object thre is no events section @alymurtazamemon
Beta Was this translation helpful? Give feedback.
All reactions
-
Hey @alymurtazamemon , I rolled back to ether v5 but now I am getting following error
TypeError: (0 , ethers_1.getAddress) is not a functionI have commited changes in the repo.
Hi @harry2855 - did you ever find a solution to the error: TypeError: (0 , ethers_1.getAddress) is not a function?
Beta Was this translation helpful? Give feedback.
All reactions
-
Have you tried with contract.address?
Beta Was this translation helpful? Give feedback.
All reactions
-
I was getting the same error. In my case @nomiclabs/hardhat-ethers was causing the problem. The following version solved it.
@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13Beta Was this translation helpful? Give feedback.
All reactions
-
hi Mohammed, thank you that seems to have worked.
I wonder why the previous project (i copied the package.json file from the older project) didn't through up the same error?
Anyway, thanks for your help!
I ultimately finished lesson 14 with ethers v6 without reading the SubId from the event triggered. Still struggling to read emitted events using ethers v6. If anyone can point me in the right direction that would be awesome. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions
-
Ahmed, have you (or anyone else) found out why the subscription ID is not being emitted in ehters v5?
Beta Was this translation helpful? Give feedback.