The VRF Oracle allows users to create subscriptions to fund on-chain requests for random numbers. Subscriptions have the following components:
For Pythia VRF to fulfill your requests, you must maintain a sufficient amount of token in your subscription balance. Gas cost calculation includes the following variables:
The gas price depends on current network conditions. The callback gas depends on your callback function, and the number of random values in your request. The cost of each request is final only after the transaction is complete.
Requests to VRF follow the request and receive data cycle. This end-to-end diagram shows each step in the lifecycle of a VRF subscription request, and registering a smart contract with a VRF subscription account:
Two types of accounts exist in the Ethereum ecosystem, and both are used in VRF:
The VRF solution uses both off-chain and on-chain components:
Set up your consuming contract:
VRFConsumer
.fulfillRandomWords
function, which is the callback VRF function. Here, you add logic to handle the random values after they are returned to your contract.requestRandomWords
of the VRF Coordinator. Include the following parameters in your request:keyHash
: Identifier that maps to a job and a private key on the VRF service and that represents a specified gas lane. If your request is urgent, specify a gas lane with a higher gas price limit. The configuration for your network can be found here.subscriptionId
: The subscription ID that the consuming contract is registered to. Funds are deducted from this subscription.numberOfRandoms
: The number of random numbers to request. The maximum random values that can be requested for your network can be found here.callbackGasLimit
: The maximum amount of gas that can be used for the callback function. This limit is set to prevent excessive gas usage. If the callback function requires more gas than this limit, the request will fail. The gas limit should be set according to the complexity of your callback function.After you submit your request, it is processed using the Request & Receive Data cycle. The VRF coordinator processes the request and determines the final charge to your subscription using the following steps:
Security Considerations
Using Pythia VRF solution brings high quality randomness into your applications, but in order or achieve high security and true fairness you should keep some security conciderations in your mind.
Get a Random
This guide will help you understand how to create a basic contract to request and receive random values from Pythia VRF.