Verifiable Random Numbers (VRN)
A guide to generating Verifiable Random Numbers (VRNs) in your smart contract using LinkWell Nodes's cryptographically secure and verifiable random number generation (RNG) service.
On this page:
Overview
LinkWell Nodes's Verifiable Random Numbers (VRN) service is a cryptographically-secure random number generator (RNG) that sends random numbers to your on-chain smart contract.
Unlike traditional random number generators, VRN allows you to independently verify that the numbers provided were generated fairly, using a pre-committed secret seed.
Is LinkWell's VRN the same as Chainlink's VRF?
No. VRN is a different service that provides a similar level of security and verifiability, but added ease of implementation, free testnet usage, and minimal-cost mainnet usage. For more information, visit our feature comparison table.
Features
- Cryptographically Secure: Seeds are generated randomly using a secure cryptographic hashing algorithm
- Verifiable: All random numbers can be independently verified using the seed
- Tamper-Proof: Seeds are revealed only after a delay, preventing manipulation
- Custom Ranges: Specify your desired min and max random number value, saving costly gas otherwise required to normalize the result upon receiving it
- Multiple Values: Request just one random number, or multiple random numbers at once, saving time and gas otherwise required to make multiple requests
- Gas Efficient: Computation happens off-chain, minimizing gas costs
Key concepts
Seed Generation
- Our infrastructure generates a new cryptographically-secure random seed every 6 hours (also known as an 'epoch')
- Each seed is hashed and stored securely on our SOC-2 compliant infrastructure
- Seeds only become publicly available once their respective epoch has ended, to prevent manipulation
Random Number Request
- Your smart contract's
request()
function requests a random number within the specifiedminVal
andmaxVal
(inclusive) - Our oracle uses the current epoch's secret seed to generate your random number
- Our oracle returns both the random number and the seed's one-way hash to your smart contract
- Your smart contract's
Verification
LinkWell Nodes VRN vs. Chainlink Labs VRF
LinkWell Nodes' VRN (Verifiable Random Numbers) service is a comparable alternative to Chainlink Labs' VRF (Verifiable Random Function) service. Below is a feature comparison table to help you decide which option is right for your business.
Full feature comparison table
Feature | LinkWell Nodes VRN | Chainlink Labs VRF |
---|---|---|
Randomness generation | Yes | Yes |
Configurable range (min/max) | Yes | No |
Verifiability | Yes | Yes |
Ease of integration | Easy | Medium |
Supported networks | 14 | 7 |
Cost | Typically lower | Typically higher |
Pay in LINK | Yes | Yes |
Pay in native gas token | Yes | Yes |
Pay in stablecoins | Yes | No |
Pay in fiat | Yes | No |
Response time (blocks) | 2-3 (chain-dependent) | 2-3 (chain-dependent) |
Infrastructure | Private, SOC-2 compliant infrastructure | Decentralized oracle network (DON) |
Free monitoring | Yes (mainnet requests) | No |
Free dedicated support | Yes (mainnet requests) | No |
Implementation guide
Step 1: Deploy your VRN consumer contract
Deploy your own VRN consumer contract to start requesting verifiable random numbers:
Visit our Data Feeds page and navigate to your desired blockchain network and data type to find the appropriate VRN consumer contract.
Example:
Testnets
->Base Sepolia
->uint256
->A random number (VRN / RNG)
Step 2: Request a random number
Call the request()
function within your deployed contract, with your desired range specified.
The oracle will respond by calling your contract's fulfill()
function with:
- A request ID (
requestId
) - Random number(s) within your specified range (
_randomNumber
or_randomNumbers
) - The one-way hash of the secret seed used to generate your number(s) (
hash
)
Step 3: Verify the random number(s)
You have two options for verifying your random number(s):
You must wait for respective seed's epoch to end (every 6 hours) before you can verify your random number(s). Epochs end at the following times each day:
- 00:00:00 UTC
- 06:00:00 UTC
- 12:00:00 UTC
- 18:00:00 UTC
Option 1 (off-chain): Using our website
Call the
getHash(requestId)
function, passing in the requestId in questionVisit our seed verification page, entering your chain ID and hash as URL parameters:
https://linkwellnodes.io/VRN-Seed.html?chain=ENTER_CHAIN_ID_HERE&hash=ENTER_HASH_HERE
chain
: The chain ID for your respective blockchain network can be found at chainlist.orghash
: The hash obtained from thegetHash(requestId)
call within your contract
If the seed is available, it will be shown on the page
Call
verifyResult(requestId, seed)
with the requestId and the retrieved seed- A return value of
true
confirms that the randomness was verified on-chain
- A return value of
Option 2 (on-chain): Using an oracle request
Ensure your contract has sufficient LINK token balance
Call
requestSeedFromOracle(requestId)
with your requestId- This will send LINK to our oracle as payment for this transaction
- The required amount of LINK has been pre-specified within this function, and cannot be changed
Wait several blocks for our oracle to call
fulfillSeedFromOracle()
- If the seed is available, this will write the seed to your contract's storage
Call
verifyResult(requestId)
- A return value of
true
confirms that the randomness was verified on-chain
- A return value of
The logic used for verifying a given random number is as follows:
randomNumber = uint256(keccak256(abi.encodePacked(
seed, // Secret seed for the related epoch
address(this), // Your contract address (prevents cross-contract replay attacks)
requestId, // Unique request ID (prevents replay attacks within your contract)
index // The 0-indexed index of the requested number (0 for requests for a single number)
))) % (maxVal - minVal + 1) + minVal; // The requested lower and upper bounds of the random number(s) (inclusive)
Security
Our VRN service employs multiple security measures:
- Seeds are generated using cryptographically-secure hashing algorithms
- Seeds are encrypted and stored on our secure, SOC-2 compliant infrastructure until their designated reveal time
- Seeds are rotated every 6 hours to prevent manipulation
- All random number generation follows a deterministic and verifiable process
- All operations are verifiable on-chain
Need more help?
Join our Discord server for immediate assistance!