Lesson 9: How to get requestId from VRFCoordinatorV2Mock RandomWordsRequested event #3656
emilianolch
started this conversation in
Show and tell
Replies: 1 comment
-
Awesome, this is great! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As Patrick suggested in performUpkeep unit testing, there's no need to emit an event here because VRFCoordinator already emits one when a random number is requested. So, I got rid of RequestedRaffleWinner event in Raffle contract. But then I ran into an issue when I tried to get the requestId in the test. It seems that when the event doesn't come from the contrarct that initiated the transaction, the event data is not parsed, hence you can't access to args.
If you wanted to get requestId this way:
const requestId = txReceipt.events[0].args.requestId;
you'll get this error:
TypeError: Cannot read properties of undefined (reading 'requestId')
In order to be able to get requestId from VRFCoordinator event you should do this:
const requestId = vrfCoordinatorMock.interface.parseLog( txReceipt.events[0] ).args.requestId;
Beta Was this translation helpful? Give feedback.
All reactions