Verifiable Random Function (VRF)
Fast, secure, and affordable onchain random number generation.
Welcome to Proof of Play’s VRF documentation. We’ve been running this VRF at scale for Pirate Nation on Polygon, Arbitrum Nova, Proof of Play Apex, Proof of Play Boss, and Abstract. Chains with over 75 million numbers served.
This VRF is primarily focused on serving random numbers as fast as possible to reduce users latency. On chains like Proof of Play Apex and Proof of Play Boss we see average times from requested to delivered being 1500ms. Please note, depending on chain speed this number can vary.
We’re inviting you as a special use case to try this out as part of our closed-alpha phase.
Registration
During early access, all users of the VRF system must be manually registered. In order to use the system your contract address must be approved, otherwise any requests to use the VRF will revert.
Contract Addresses
Network | Address |
---|---|
Abstract Testnet | 0xC04ae87CDd258994614f7fFB8506e69B7Fd8CF1D |
Abstract Mainnet | 0xBDC8B6eb1840215A22fC1134046f595b7D42C2DE |
Usage
Requesting a Random Number
The following interface provides a method for requesting random numbers.
Your contract can call the VRFSystem deployed on each chain. You can optionally provide a traceId, which will be annotated to each event (Useful if you have one transaction that does many VRF steps, users can trace their transactions on chain). This is not required and can be left as 0.
Random Number Callbacks
Every random number requested is delivered as soon as the first available number from drand is available to be delievered. This can take as long as 3 seconds.
What if I want to have different numbers in the same 3 second window?
By default, we deliver the same number to all requests inside the same 3 second window that drand provides. This is great to be able to verify, but if you would like to have users all have different numbers over this time period, we recommend you add a source of entropy.
Here’s a couple of examples of having unique random numbers per transaction.
Note: These are not guaranteed to be normalized, but will retain the randomness properties of the above. We recommend adjusting to your liking to achieve more or less normalized (for instance, adding sequenceId to the randomNumber would be very skewed, whereas using a blockhash would be very normalized).
If you would like to have different numbers on the same block, recommend re-hashing the same number multiple times in the same transcation
Blockchain Events
The contract will emit the following events.
You can query these events on RPC level to see if they were delivered or use the block explorer to view a stream of events.
Verifying the round number / random number with drand
If you want to verify the random number, you can check directly with drand for this. We use drand’s quicknet for this.
For instance, to see the roundNumber 11:
GET https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971/public/11
We can see here the random number in hex is ebdcbfe855d10c56db22455fa5a18963c1f62d85f859c35c310273449b49d284
Manual Retries
In a very rare instance, you may see random numbers fail to be recieved. In most cases this will be an issue on the contract side. But if you wish to manually retry you can set a GET request.