Below you may find a simplified example of a contract requesting a random number and receiving the callback containing the random number and the proof.
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;interface IVRFConsumer {functionrequestRandomness(uint256 seed) externalreturns (uint256);}contract SimpleVRFContract {uint256public lastRequestId;bytes32public lastRandomNumber;bytespublic lastProof;functionrequestRandomNumber(uint256 seed) external {// Initialize the interface for the VRFConsumer contract IVRFConsumer vrfConsumer =IVRFConsumer(0x7efDa6beA0e3cE66996FA3D82953FF232650ea67);// Request randomness from the VRFConsumer contract lastRequestId = vrfConsumer.requestRandomness(seed); }functionrandomnessCallback(bytes32 randomNumber,uint256 requestId,bytesmemory proof ) external {// Ensure the caller is the VRFConsumer contractrequire( msg.sender ==address(0x7efDa6beA0e3cE66996FA3D82953FF232650ea67),"Only the VRFConsumer can call this function" );// Check if the requestId matches the lastRequestIdrequire(requestId == lastRequestId,"Request ID does not match the last request");// Store the results lastRandomNumber = randomNumber; lastProof = proof;// Handle the random number and complete your game logic here }}
We say simplified because we do not verify the proof and we do not validate that the random number was generated by the VRF private key.
Move on the the next section to learn more about how it works and how we can optionally verify this information on chain.