Examples
Examples
Quick Start: Minimal Integration
Here's a minimal example of how to request verifiable randomness from SimpleVrf in your Fuel contract:
- Implement the callback to receive the proof.
- Call
request_random_number(seed)
to request randomness.
Full Example: Advanced Contract Integration
Below is a full example of a Fuel contract integrating with SimpleVrf for verifiable randomness, including storage and helper functions:
How it works
- The contract implements a callback interface (
SimpleVrfCallback
) to receive the random proof. - The
request(seed)
function stores the seed, fetches the fee, and calls the SimpleVrf contract to request randomness. - The callback (
simplevrf_callback
orsimple_callback
) is triggered by SimpleVrf when the proof is ready, storing the result in contract storage. - Helper functions allow reading the latest proof and seed, and setting the VRF contract address.
You can use this pattern to integrate verifiable randomness into your own Fuel contracts. For more, see the SimpleVrf ABI documentation.