This repository provides example contracts and instructions for setting up Verifiable Random Function (VRF) on Gelato, utilizing Gelato VRF.
Verifiable Random Function (VRF) is a cryptographic primitive that generates unpredictable random numbers. Integrating VRF into Gelato allows for various decentralized applications (DApps) to leverage secure, on-chain randomness.
This repository includes contracts and configurations necessary for implementing VRF functionality on Gelato, making it easy for developers to integrate random number generation into their projects.
Before beginning, make sure you have the following installed or set up on your computer beforehand.
- nvm or Node
v20.0.0or greater - npm or yarn
- Wallet that contains BERA token (for deployment, use the Bepolia faucet from BeraHub)
- hardhat
Create a .env file at the project root and populate it with the following values
PRIVATE_KEY=<YOUR PRIVATE KEY>
DEDICATED_MSG_SENDER=<YOUR DEDICATED MSG SENDER>
SC_ADDRESS=<smart contract deployed in this guide>cp .env.example .envTo deploy the SimpleVRFContract, you'll need to install the dependencies first
npm installThen run the following hardhat command:
npx hardhat deploy --network berachainBepoliaNote
Check the deployed addresses for each network in the deployments/ folder, which is automatically created at the root of the gelato-vrf/ directory following a deployment.
- Description: Contract for using Gelato VRF directly.
- Contract Address on Berachain: use the address from your own deployment.
- Features:
- Requests randomness from Gelato VRF.
- Handles the fulfillment of randomness.
Deploying your Gelato VRF instance is a straightforward process. Here's a step-by-step guide to get you started:
Before you begin, make sure you have the address of your requester contract at hand. This will be essential for the deployment process.
Navigate to the Gelato app.
Ensure you choose the Berachain Bepolia network where your VRF requester and receiver contracts are deployed.
You'll be asked to provide the address of the Request Contract to which the Gelato nodes should respond. Enter the address you gathered in step 1.
Once all details are correctly entered, go ahead and launch your Gelato VRF instance.
After deploying your contract, proceed to the .env file and replace the existing smart contract address with the one specific to your deployment.
SC_ADDRESS=<your deployed contract address>To invoke the randomness request, you can run the requestRandomness.ts script:
npx hardhat run ./scripts/requestRandomness.ts --network berachainBepoliaThis will produce a similar response:
Requesting randomness with data: 0x7465737420646174610000000000000000000000000000000000000000000000
Transaction hash: 0x1a33e33970c0c4e89589e863b8833d7da5138a4f13b7cc02da9b2d97863912df
After your randomness request has been made, monitor it from your Gelato VRF task page.


