Generate cryptographically secure random numbers with on-chain verification. Built for Solana's high-performance ecosystem.
use anchor_lang::prelude::*;
#[program]
pub mod vrf_program {
use super::*;
pub fn initialize(ctx: Context) -> Result<()> {
Ok(())
}
pub fn request_random(
ctx: Context,
seed: [u8; 32]
) -> Result<()> {
// Request random value from VRF
let request_id = ctx.accounts
.vrf_program
.request_random(seed)?;
// Store request info for callback
ctx.accounts.request_account.id = request_id;
ctx.accounts.request_account.requester = *ctx.accounts.requester.key;
ctx.accounts.request_account.bump = *ctx.bumps.get("request_account").unwrap();
// Emit request event
emit!(RandomnessRequested {
id: request_id,
requester: *ctx.accounts.requester.key,
seed,
timestamp: Clock::get()?.unix_timestamp,
});
Ok(())
}
pub fn consume_random(
ctx: Context,
value: [u8; 32],
proof: VrfProof
) -> Result<()> {
// Verify VRF proof
require!(
verify_vrf_proof(&proof, &value),
VrfError::InvalidProof
);
// Process the random value
let random_number = process_vrf_output(&value);
// Emit completion event
emit!(RandomnessReceived {
request_id: ctx.accounts.request_account.id,
value,
proof,
timestamp: Clock::get()?.unix_timestamp,
});
Ok(())
}
}
Secure Randomness for Web3
Generate provably fair random numbers with cryptographic verification for your Solana programs.
Every random number comes with a VRF proof that can be verified on-chain using Solana's native cryptographic primitives.
Cryptographically secure generation process prevents manipulation of random values, ensuring fair and unbiased results.
Fast random number generation and verification leveraging Solana's speed and performance.
Multiple independent validators participate in random number generation and verification.
Pay for VRF requests in native SOL. No additional token setup required.
VRF protocol evolves through DAO governance using Solana's native governance framework.