Lesson 9 Lottery: How does performUpkeep() actually call the fulfillRandomWords() function? #304
-
My code compiles and I'm already at the tests part, but now that I go back to the contract I don't understand how the performUpkeep() function calls the fulfillRandomWords() function. What am I missing? There's no function call for fulfillRandomWords() inside performUpkeep(). function performUpkeep(
bytes calldata /*performData*/
) external override {
// checkUpkeep returns two values and takes one value
(bool upkeepNeeded, ) = checkUpkeep("");
if (!upkeepNeeded) {
revert Raffle__UpkeepNotNeeded(
address(this).balance,
s_players.length,
uint256(s_raffleState)
);
}
s_raffleState = RaffleState.CALCULATING;
uint256 requestId = i_vrfCoordinator.requestRandomWords(
i_gasLane, // gasLane
i_subscriptionId,
REQUEST_CONFIRMATIONS,
i_callbackGasLimit,
NUM_WORDS
);
emit RequestedRaffleWinner(requestId);
}
function fulfillRandomWords(
uint256, /*requestId*/
uint256[] memory randomWords
) internal override {
uint256 indexOfWinner = randomWords[0] % s_players.length;
address payable recentWinner = s_players[indexOfWinner];
s_recentWinner = recentWinner;
s_raffleState = RaffleState.OPEN;
s_players = new address payable[](0);
s_lastTimeStamp = block.timestamp;
// Send winner the money
(bool success, ) = recentWinner.call{value: address(this).balance}("");
if (!success) {
revert Raffle__transferFailed();
}
emit WinnerPicked(recentWinner);
} |
Beta Was this translation helpful? Give feedback.
Answered by
PatrickAlphaC
Jun 13, 2022
Replies: 1 comment
-
A chainlink node later will then respond by calling the Feel free to watch the walkthrough: https://www.youtube.com/watch?v=rdJ5d8j1RCg |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
PatrickAlphaC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
performUpkeep
callsrequestRandomWords
- which kicks off a Chainlink VRF Request.A chainlink node later will then respond by calling the
fulfillRandomWords
function!Feel free to watch the walkthrough: https://www.youtube.com/watch?v=rdJ5d8j1RCg