Request Randomness
Once you have the interface declared you can call the contract to request the random number. The only argument this function takes is a seed which you can generate. In this example, the seed is a hash of the previous block timestamp and the address of the caller.
function requestRandomNumber() external {
// Perform your game functions here possibly and
// request your random number at the end
bytes32 seed = keccak256(
abi.encodePacked(block.timestamp, msg.sender)
);
IVRFConsumer vrfConsumer = IVRFConsumer(0x7efDa6beA0e3cE66996FA3D82953FF232650ea67);
uint256 requestId = vrfConsumer.requestRandomness(seed);
}
You should store the requestId
in your contract if you want to match the response callback to the original request.
Last updated