Error while getting Random words from VRFC2PlusClient. #2063
-
In the following function: function performUpkeep(bytes calldata /* performData */) external {
// Check if enough time has passed.
if ((block.timestamp - s_lastTimeStamp) <= i_interval) {
revert();
}
(bool upkeepNeeded, ) = checkUpkeep(bytes(""));
if (!upkeepNeeded) {
revert Raffle__upkeepNotNeeded(
address(this).balance,
s_players.length,
uint256(s_raffleState)
);
}
s_raffleState = RaffleState.CALCULATING;
// Get our random number
// It is more like a 2 step process:
// 1. Request a random number generator
// 2. Get the random number from the generator.
VRFV2PlusClient.RandomWordsRequest memory request = VRFV2PlusClient
.RandomWordsRequest({
keyHash: i_keyHash,
subId: i_subscriptionId,
requestConfirmations: REQUEST_CONFIRMATIONS,
callbackGasLimit: i_callbackGasLimit,
numWords: NUM_WORDS, // Number of Random numbers required
extraArgs: VRFV2PlusClient._argsToBytes(
VRFV2PlusClient.ExtraArgsV1({nativePayment: false})
)
});
// Request random words
uint256 requestId = s_vrfCoordinator.requestRandomWords(request); // Why this doesnot work?
} when I am making the last request for the
Can someone help me with this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 19 replies
-
Hello @PrashikshitSaini, The below is what my own function that works look like function performUpkeep(bytes calldata /* performData */) public {
(bool upkeepNeeded,) = checkUpkeep("");
if(!upkeepNeeded) revert Raffle__LotteryDoesNotNeedUpdate();
s_raffleState = RaffleState.CALCULATING;
console2.log("The address of the lottery contract is: ", address(this));
uint256 requestId = i_vrfCoordinatorContract.requestRandomWords(VRFV2PlusClient.RandomWordsRequest({
keyHash: i_gasLane,
subId: i_subscriptionId,
requestConfirmations: REQUEST_CONFIRMATIONS,
callbackGasLimit: CALLBACK_GAS_LIMIT,
numWords: NUM_OF_WORDS,
// Set nativePayment to true to pay for VRF requests with Sepolia ETH instead of LINK
extraArgs: VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: false}))
}));
emit Raffle__randomNumberRequested(requestId);
} |
Beta Was this translation helpful? Give feedback.
-
Please replace the below code in your current contract VRFV2PlusClient.RandomWordsRequest memory request = VRFV2PlusClient.RandomWordsRequest({
keyHash: i_keyHash,
subId: i_subscriptionId,
requestConfirmations: REQUEST_CONFIRMATIONS,
callbackGasLimit: i_callbackGasLimit,
numWords: NUM_WORDS, // Number of Random numbers required
extraArgs: VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: false}))
});
// Request random words
uint256 requestId = s_vrfCoordinator.requestRandomWords(request); // Why this doesnot work? With this uint256 requestId = s_vrfCoordinator.requestRandomWords(VRFV2PlusClient.RandomWordsRequest({
keyHash: i_keyHash,
subId: i_subscriptionId,
requestConfirmations: REQUEST_CONFIRMATIONS,
callbackGasLimit: i_callbackGasLimit,
numWords: NUM_WORDS, // Number of Random numbers required
extraArgs: VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: false}))
})); Let's see it resolve the error. I am looking forward to hear from you. |
Beta Was this translation helpful? Give feedback.
-
@PrashikshitSaini thank you sir. it has work for me |
Beta Was this translation helpful? Give feedback.
-
Awesome. |
Beta Was this translation helpful? Give feedback.
Thank You mate @EngrPips ,
BUT
Just removing the import won't work because the contract is not aware of the
VRFV2PlusClient.sol
.So to remove the redundancy, I imported
IVRFCoordinatorV2Plus.sol
:Again, thanks for fixing it with me.