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?


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. *

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

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.