Lesson 9: Unable to retrieve requestId #698
-
it("tests if raffle is CALCULATING, emits an event, and calls the vrf coordinator", async function () {
await raffle.enterRaffle({ value: entryFee })
await network.provider.send("evm_increaseTime", [
raffleInterval.toNumber() + 1,
])
await network.provider.send("evm_mine", [])
const txResponse = await raffle.performUpkeep([])
const txReceipt = await txResponse.wait(1)
const requestId = await txReceipt.events[1].args.requestId // upar ka func emits an event
raffleState = await raffle.getRaffleState()
assert.equal(raffleState.toString(), "1")
//assert(requestId > 0)
expect(requestId.toString()).to.be.greaterThan("0")
}) Unable to retrieve requestId from the above code. I'm getting the following error:
My performUpkeep function is like this: function performUpkeep(
bytes calldata /* performData */
) external override {
// we made this function to be external because we wont call it from inside our function, and overall external fun are cheaper
// pick a Random Winner
// do something with it
// 2 transaction process
(bool upkeepNeeded, ) = checkUpkeep(""); // "" because we dont want to pass anything in the calldata of 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_keyHash,
i_subscriptionId,
REQUEST_CONFIRMATIONS,
i_callbackGasLimit,
NUM_WORDS
); // this will return a uint256 which we can store
emit RequestedRaffleWinner(requestId);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Try commenting out these lines one at a time to identify if the issue comes from here: Also, you may want to try to use |
Beta Was this translation helpful? Give feedback.
-
In my case, to get the |
Beta Was this translation helpful? Give feedback.
In my case, to get the
requestId
I had to dotxReceipt.events[1].args[0]
. Hopefully that helps you 🙂