When you request random number, the Chainlink VRF2 returns it by calling following function.

function fulfillRandomWords(
        uint256, /* requestId */
        uint256[] memory randomWords
    ) internal override {
        s_randomWords = randomWords;
        randomNum = s_randomWords[0];

There is not guaranteed time. What is the best way to catch when it is arrived?

What I have:

def request_random():
    account = get_account()
    contract = AdvancedCollectible[-1]

    # Request Random
    tx = contract.requestRandom({"from": account})

    print("Waiting for the callback...")


    while True:
        random_num = contract.randomNum()

        if random_num != 0:
            print("Finally received random num:", random_num)
            print("Waiting another 5 sn")

Another way would be events but since fulfillRandomWords function is called by coordinator, I can't create a transaction to listen event of this function.

I am sure there is better way to do so...

  • I'd use an event, if it is triggered by your contract you can use its address to filter the events.
    – Ismael
    Apr 21 at 4:12
  • Fallack function is triggered automatically. Thus, I cant access the event emiitted in it
    – Emrah
    Apr 21 at 4:46
  • You could modify fulfillRandomWords to trigger the event from there.
    – Ismael
    Apr 21 at 4:56

1 Answer 1


You can create a custom event for the randomNumberConsumer contract that you can listen for in a client (such as a frontend or javascript client).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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