GeneralRandcastConsumerBase
The GeneralRandcastConsumerBase
contract aims to simplify the process of requesting and consuming randomness provided by Randacst. This contract combines the following aspects: requestId
generation, gas estimation, callback handling, and gas limit/gas fee configuration.
Here is a detailed breakdown of what the GeneralRandcastConsumerBase
contract does:
Imports the necessary contracts and libraries:
RequestIdBase
helps generate unique request IDs for randomness requests.
GasEstimationBase
aids in calculating the gas needed for the callback functions.
BasicRandcastConsumerBase
is the base contract for handling randomness requests and fulfillment.
Lastly, OpenZeppelin's Ownable
contract is used for access control.
Inherits the imported contracts and libraries:
Sets important constants:
The variables represent the user seed placeholder, the gas overhead for callback execution, and a placeholder for initial entropy.
Defines public variables for callback gas limit, max gas fee, and request confirmations(blocks):
Note: These variables can be set manually or calculated automatically.
Provides the setCallbackGasConfig()
function and setRequestConfirmations()
function to allow the owner to set the callbackGasLimit
, callbackMaxGasFee
and requestConfirmations
manually:
setCallbackGasConfig()
function and setRequestConfirmations()
function to allow the owner to set the callbackGasLimit
, callbackMaxGasFee
and requestConfirmations
manually:Implements the requestRandomness()
function for requesting randomness from the Adapter:
requestRandomness()
function for requesting randomness from the Adapter:This function takes requestType
and params
as arguments and estimates the required gas for the user-implemented callback function when callbackGasLimit
is not set.
Estimates the required gas for the callback function:
When the callbackGasLimit
is not set, this function will estimate the required gas for the callback function based on the request type.
Sends a raw randomness request to the Adapter:
The rawRequestRandomness()
function sends the randomness request to the Adapter with the proper parameters, including the request type, params, subscription ID, user seed, request confirmations, callback gas limit, and callback max gas price. If the callbackMaxGasFee
is not set, it defaults to three times the transaction gas price. If requestConfirmations
is not set, it defaults to minimumRequestConfirmations
in the Adapter config.
In summary, the GeneralRandcastConsumerBase
contract provides an extendable base for contracts that need to request randomness from Randcast. It streamlines requesting and receiving randomness by automating nonce management, gas estimation, and callback handling.
Additionally, it allows manual configuration of requestConfirmations
, callback gas limits and fees for flexibility.
Note: To know more about the implementation, please refer to the full source code of the smart contract.
Next, we will look at an example of requesting a random number by extending GeneralRandcastConsumerBase
.
Last updated