0

I've followed this tutorial, but when I tried to call function RandomNumberConsumerV2.requestRandomWords, I got the following error:

[vm]from: 0x5B3...eddC4to: RandomNumberConsumerV2.requestRandomWords() 0xf8e...9fBe8value: 0 weidata: 0xe0c...86289logs: 0hash: 0xabf...52f88
status 0x0 Transaction mined but execution failed
transaction hash 0xabf401e7bd296b1dbf84e024fbae6af58fbb4ffc06ad5c9a047e7e874e252f88
block hash 0x203a4ded518503050b091bc81504b692ab7d5fa4978c0b8f39638dce50867da3
block number 4
from 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
to RandomNumberConsumerV2.requestRandomWords() 0xf8e81D47203A594245E36C48e151709F0C19fBe8
gas 3000000 gas
transaction cost 26834 gas
execution cost 5770 gas
input 0xe0c...86289
decoded input {}
decoded output {}
logs []
transact to RandomNumberConsumerV2.requestRandomWords errored: Error occurred: revert.

revert
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
You may want to cautiously increase the gas limit if the transaction went out of gas.

Thanks in advance.

2
  • Which network are you using? Commented May 16 at 18:05
  • as mentioned in the tutorial local network in remix . not any testnet like sepolia or etc ... thanks for asking.
    – rebwar
    Commented May 16 at 18:41

1 Answer 1

0

You might be deploying the VRFCoordinatorV2Mock and RandomNumberConsumerV2 on different instances of Remix IDE (i.e., on different tabs). So, they're not having the context of each other due to the local network deployment as the instances of local node operate separately and gets reinitialised on opening any new instance of the IDE or even on refreshing the page.

Therefore, when you deploy RandomNumberConsumerV2 and pass the vrfCoordinator address as one of its constructor param, then it just uses it as a dummy address, not as an actual address of deployed VRFCoordinatorV2Mock.

And the same thing happens when you call the addConsumer function of VRFCoordinatorV2Mock by passing the address of the deployed RandomNumberConsumerV2 in the value of _consumer address.

So, they have to be present in the same instance of the IDE:

enter image description here

And, deployed in the same instance as well:

enter image description here

After that, proceed with the steps mentioned in the docs as calling createSubscription, followed by fundSubscription, and then calling addConsumer.

If you do everything in the correct sequence, then calling the requestRandomWords function should work fine, as it worked in my case:

enter image description here

Received the s_requestId successfully:

enter image description here

Then, called the fulfillRandomWords function of VRFCoordinatorV2Mock:

enter image description here

And, finally got the random words in s_randomWords array:

enter image description here

enter image description here

2
  • thanks Dear @SYED
    – rebwar
    Commented May 17 at 10:31
  • You're welcome @rebwar. Happy coding! Commented May 17 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.