Quickstart
This page deploys a new consumer with the Ronin VRF interface, which every Randoo network serves: Ronin, Base and Robinhood. If you already use another VRF, its migration guide is shorter: from Ronin VRF, from Chainlink VRF v2.5, from D20DAO, from Pyth Entropy or from Gelato VRF.
Consumer
Copy three files into a Foundry project (forge init). Put each one at the path below, because the imports expect it.
src/RandooConsumerRonin.solis the base contract. It stores the coordinator, accepts only the coordinator's callback, and sends requests.src/interfaces/IRoninVRFCoordinatorForConsumers.solis the coordinator interface.test/templates/TemplateConsumer.solis a minimal consumer. Rename it, and put your game logic in_fulfillRandomSeed. If you move it, fix its import path.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IRoninVRFCoordinatorForConsumers} from "./interfaces/IRoninVRFCoordinatorForConsumers.sol";
/// @notice Ronin VRFConsumer-shaped base. Swap coordinator address to migrate.
abstract contract RandooConsumerRonin {
error OnlyCoordinatorCanFulfill();
address public vrfCoordinator;
constructor(address vrfCoordinator_) {
vrfCoordinator = vrfCoordinator_;
}
function rawFulfillRandomSeed(bytes32 reqHash, uint256 randomSeed) external {
if (msg.sender != vrfCoordinator) revert OnlyCoordinatorCanFulfill();
_fulfillRandomSeed(reqHash, randomSeed);
}
function _fulfillRandomSeed(bytes32 reqHash, uint256 randomSeed) internal virtual;
function _requestRandomness(
uint256 value,
uint256 callbackGasLimit,
uint256 gasPriceToFulfill,
address refundAddr
) internal returns (bytes32 reqHash) {
reqHash = IRoninVRFCoordinatorForConsumers(vrfCoordinator).requestRandomSeed{value: value}(
callbackGasLimit,
gasPriceToFulfill,
address(this),
refundAddr
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @dev Byte-compatible with Ronin VRF's consumer-facing coordinator.
interface IRoninVRFCoordinatorForConsumers {
function requestRandomSeed(
uint256 callbackGasLimit,
uint256 gasPrice,
address consumer,
address refundAddress
) external payable returns (bytes32 reqHash);
function estimateRequestRandomFee(uint256 callbackGasLimit, uint256 gasPrice) external view returns (uint256);
}
interface IRoninVRFConsumer {
function rawFulfillRandomSeed(bytes32 reqHash, uint256 randomSeed) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// ---------------------------------------------------------------------------
// Randoo consumer template: copy-pasteable as a unit with
// RandooConsumerTemplate.t.sol and MockRandooCoordinator.sol (this folder), plus
// src/RandooConsumerRonin.sol and src/interfaces/IRoninVRFCoordinatorForConsumers.sol.
// Imports resolve in a fresh `forge init` with only forge-std installed.
// ---------------------------------------------------------------------------
import {RandooConsumerRonin} from "../../src/RandooConsumerRonin.sol";
/// @notice The canonical Randoo consumer. Copy it, rename it, put your game
/// logic in `_fulfillRandomSeed`.
///
/// Flow: a caller pays `estimateRequestRandomFee(callbackGasLimit, gasPrice)`
/// into `roll`, which forwards the request to the coordinator and returns the
/// `reqHash`. Later the coordinator calls `rawFulfillRandomSeed` (inherited,
/// coordinator-only) which lands in `_fulfillRandomSeed` with the seed.
contract TemplateConsumer is RandooConsumerRonin {
/// @notice Last seed delivered by the coordinator.
uint256 public lastSeed;
/// @notice Request hash of the most recent `roll`, then of the most recent fulfil.
bytes32 public lastReqHash;
constructor(address vrfCoordinator_) RandooConsumerRonin(vrfCoordinator_) {}
/// @param callbackGasLimit Gas the coordinator will give `_fulfillRandomSeed` (50k..2.5M).
/// @param gasPrice Gas price the fulfiller may spend; must be >= the coordinator floor.
/// @param refundAddr Receives unspent fulfilment gas; must be non-zero.
function roll(
uint256 callbackGasLimit,
uint256 gasPrice,
address refundAddr
) external payable returns (bytes32 reqHash) {
reqHash = _requestRandomness(msg.value, callbackGasLimit, gasPrice, refundAddr);
lastReqHash = reqHash;
}
/// @dev Your randomness lands here. Keep it within `callbackGasLimit`.
function _fulfillRandomSeed(bytes32 reqHash, uint256 randomSeed) internal override {
lastReqHash = reqHash;
lastSeed = randomSeed;
}
}The integration playbook has a mock coordinator and a test suite for this template. For complete contracts built on the same base, see Loot box with VRF (weighted drops, a fallback for failed callbacks, measured callback gas), NFT reveal with VRF (a provenance hash and one random offset for a whole ERC-721 collection), Raffle with VRF (weighted tickets, one draw, a prize the winner withdraws) and Dice game with VRF (bets with a reserved payout, a 52-card shuffle from one seed). If players can have several requests open at once, key each one by its request hash as in Several VRF requests at once.
Deploy and request
This example uses Base Sepolia. Every network uses the same coordinator address, so only the RPC changes. Contracts lists them. dev is a keystore account you created with cast wallet import.
RPC=https://sepolia.base.org
# --constructor-args takes every value after it, so it goes last.
forge create test/templates/TemplateConsumer.sol:TemplateConsumer \
--rpc-url $RPC --account dev --broadcast \
--constructor-args 0xC66eB2e7EE91145875000Ad46B55600000000001
# Base and Robinhood: the network gas price.
GAS=$(cast gas-price --rpc-url $RPC)
# Ronin and Saigon: 23 gwei.
# GAS=23000000000
FEE=$(cast call 0xC66eB2e7EE91145875000Ad46B55600000000001 "estimateRequestRandomFee(uint256,uint256)(uint256)" \
250000 $GAS --rpc-url $RPC | cut -d' ' -f1)
cast send <consumer> "roll(uint256,uint256,address)" 250000 $GAS <your-address> \
--value $FEE --rpc-url $RPC --account dev250000is the callback gas limit. It must be between 50,000 and 2,500,000.GASis the gas price you declare for the oracle's fulfill transaction. Fees and failures explains the rule for each network.FEEis the exact prepayment. Sending less reverts withInsufficientFee.<your-address>gets back what the fulfillment does not use. It must not be the zero address.
The oracle fulfills after one confirmation. The coordinator then calls rawFulfillRandomSeed on your consumer, and the template stores the seed:
cast call <consumer> "lastSeed()(uint256)" --rpc-url $RPCUpdated 2026-11-23.