2

After executing the requestRandomness function

function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) {
    require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
    return requestRandomness(keyHash, fee, userProvidedSeed);
}

it returns the requestId by default but does it also return randomness to be used as an argument in the fulfillRandomness function?

function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
    randomResult = randomness;
}

Or do I pass in any random number as an argument for fulfillRandomness function?

2

In your requesting transaction requestRandomness returns a bytes32 and it emits an event that an off-chain Chainlink node is looking for.

Once the off-chain Chainlink node reads the event, it then creates the random number and the node is the one that calls the fulfillRandomness function**, and it passes the random number that it created along with the original requestId.

Using an off-chain oracle follows the request and receive cycle. You get the random number in the second transaction.

***techncially, the node calls the vrf coordinator which then calls the fulfillRandomness function. But don't worry about that if it's confusing. *

2
  • So when I execute the requestRandomness function it also executes fufillRandomness asynchronously?
    – user69940
    Mar 29 '21 at 10:16
  • 1
    Exactly correct. The chainlink node will actually kick off that method later in a 2nd transaction. Mar 29 '21 at 10:59

Your Answer

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