githubEdit

Request Random Numbers

Supra dVRF Contracts Architecture in EVMs

Supra dVRF uses a two-contract system:

  • Router Contract: Handles VRF requests and delivers random numbers to your callback function

  • Deposit Contract: Manages user funds, whitelisting, and gas configurations

Ready to get random? Follow these four simple steps to integrate Supra dVRF into your smart contract and start requesting verifiable random numbers.

Prerequisites

Before requesting random numbers, ensure you have:

  • ✅ Whitelisted wallet address with configured gas parameters

  • ✅ Deposited sufficient funds in the Deposit Contract

  • ✅ Whitelisted your consumer contract address

Step 1: Create the Router Interface

Add the Router Contract interface to your smart contract. This interface enables communication with Supra's VRF service. The interface provides two versions of generateRequest - use the first one if you want to provide your own seed for additional entropy, or the second one for standard random number generation.

Parameters

  • _functionSig: The signature of your callback function that will receive the random numbers (e.g., "myCallback(uint256,uint256[])")

  • _rngCount: Number of random numbers to generate in a single request (maximum 255)

  • _numConfirmations: Number of block confirmations after request transaction to wait before generating random numbers (Min:1 , Max: 20)

  • _clientSeed (optional): Your custom seed value for additional randomness (can be UUID, timestamp, etc.)

  • _clientWalletAddress: Your whitelisted wallet address that will pay for the transaction

  • Returns: uint256 nonce - A unique identifier to track your request

Step 2 : Configure Router Address

Initialize the Router Contract connection in your constructor. This binds your contract to Supra's on-chain router.

Step 3 : Request Random Numbers

Call the generateRequest function to request random numbers. This function returns a nonce that you can use to track your request and link it back to the original requester or context.

Step 4 : Implement Callback Function

Create a callback function to receive the random numbers. This function must have the exact signature: (uint256 nonce, uint256[] memory rngList). Please refer to below example. The callback validation is crucial to prevent malicious contracts from calling your function with fake random data.

Complete Example

Next Steps

After implementing the request functionality, you can:

  • Monitor your balance using Deposit Contract view functions

  • Update gas parameters for your contracts

  • Scale your random number requests based on your application needs

The random numbers generated are cryptographically secure and verifiable, making them suitable for gaming, NFT minting, and other blockchain applications requiring true randomness.

Last updated