Lesson 9: Events and arguments #1947
-
From the video, the host said that the later emitted event will be at the front of the events array from Ethers.js transaction receipt. In this case, the event RequestRaffleWinner will be placed in txReceipt.events[0] and the event emitted by i_vrfCoordinatorV2.requestRandomWords(...) will be txReceipt.events[1], am I right?The other thing is why events[0] does not have the args property that represents the request Id, but events[1] has one since I see they both have an argument requestId. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
@doz-8108 The difference is because we are not using all the parameters in requestRandomWords. To give you some context, the following event is emitted by requestRandomWords in VRFCoordinatorV2: emit RandomWordsRequested(
keyHash,
requestId,
preSeed,
subId,
requestConfirmations,
callbackGasLimit,
numWords,
msg.sender
); These are all derived from the function signature (of requestRandomWords) and since we are not using everything, the latter has more "events" emitted. |
Beta Was this translation helpful? Give feedback.
-
Hey @doz-8108 your assessment is partly true. Yes there are two events being emitted, but not in the order you put them. If you look at the code, we call the function Concerning the absence of args in the first event being emmitted, as @krakxn has explained above, we didn't declare any event with args to sort of "catch" the arguments we want. If you can remember we didn't declare anything in the events section of our raffle contract to sort of catch the event being emitted by
|
Beta Was this translation helpful? Give feedback.
Hey @doz-8108 your assessment is partly true. Yes there are two events being emitted, but not in the order you put them. If you look at the code, we call the function
i_vrfCoordinatorV2.requestRandomWords(...)
first then weemit RequestRaffleWinner(requestId)
So technically, the event at index 0 is the one emitted byi_vrfCoordinatorV2.requestRandomWords(...)
then the event at index 1 is the one emitted byRequestRaffleWinner(requestId)
That's why the first event (event at index 0) doesn't have args while the second has one arg (requestId) the one we put in the event declaration ofRequestRaffleWinner
Concerning the absence of args in the first event being emmitted, as @krakxn has explain…