2

I need to generate random number, on a single function hit and get it there only. I am not able to do that, due to block confirmations required which is set to min. 3. Is there any way to get this or to bypass block confirmation? Someone who has done this, please answer.

3 Answers 3

2

Smart contracts needs to be and are determinstic. So to truly generate verifable random number, the calculation has to take place off-chain which is why chainlink vrf takes at least 30 seconds to return the random number.

Chainlink vrf follows request and receive mechanism.

First you will request to generate a random number.

Second you will receive the random number.

There you have two transactions and the block time of ethereum is 15 seconds approx.

So you will need to wait at least for two blocks to mine before you will get the random number.

You can read more about it here: Random Numbers: Using Chainlink VRF

So the answer for your question using the chainlink vrf is no!

But you can use the other blockchains such as polygon which has much lower blocktime to achieve the same result you want.

Tell me if it helps!

3
  • That was on point. Thanks for this!! Commented Sep 21, 2022 at 7:16
  • You are welcome. Accept the answer to close the question
    – Ad-h0c
    Commented Sep 21, 2022 at 8:10
  • 1
    Done...........!! Commented Oct 6, 2022 at 18:59
2

It is impossible given the way ChainlinkVRF works. What you could do is adapt your contract to keep doing what it has to on fulfillRandomWords() but this will make the fulfillment more expensive. Another way is to trigger a function with Chainlink Keepers once your new random number is received.

2

Since the minimumRequestBlockConfirmations is set as 1, you can set requestConfirmations as 1 and that means the VRF node waits for 1 block before it sends randomness to you.

But you cannot get the randomness immediately after you send a request. There are 2 reasons:

  1. In Chainlink VRF mechanism, smart contract VRFCoordinator has to write your VRF request in the event log and waits for the off-chain VRF node to detect it. Off-chain VRF needs to get the request and then take some time to send randomness back to the blockchain, these 2 steps cannot be in the same block.

  2. VRF(Verifiable random function) algorithm takes an unpredictable seed to generate a random number. In Chainlink VRF, blockhash generated in the future is a part of the seed, so the VRF node has to wait for a block to get the unpredictable hash.

So it is impossible to get randomness right away, and, as Ad-h0c mentioned, blockchain is a deterministic system so randomness cannot be calculated on-chain 100%.

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.