This guide will help you understand how to create a basic contract to request and receive random values from Pythia VRF.
This guide assumes that you know how to create and deploy smart contracts on Canto testnets using the following tools:
You can simply create and deploy a consumer contract with your prefered tools. Here we are going to build and deploy VRFConsumer.sol
using Remix IDE.
This contract:
VRFConsumer.sol
and IVRFCoordinator.sol
.vrfCoordinator
address and keyHash
.Build and deploy the contract on Testnet.
VRFConsumer.sol
contract.VRFConsumer
contract from the contract list, and specify your subscriptionId
so the constructor can set it.The example contract is deployed and approved to use your subscription balance to pay for VRF requests. Next, request random values from VRF.
The deployed contract requests random values from Pythia VRF, receives values, builds a struct Request containing them and stores the struct in the history
mapping. Run the requestRandom()
function on your contract to start the request.
requestRandom()
function to send the request for random values. MetaMask opens and asks you to confirm the transaction. After you approve the transaction, Pythia VRF processes your request. VRF fulfills the request and returns the random values to your contract in a callback to the fulfillRandomWords()
function. A new key requestId
will add to the history
mapping.lastRequestId()
.checkRequest()
specifying the requestId
to display the random words from desired request.