RISE Logo-Light

VRF Rock-Paper-Scissors

Build an onchain rock-paper-scissors game with instant VRF randomness and gasless transactions

Introduction

In this tutorial, you'll build a fully onchain rock-paper-scissors game that uses RISE's Fast VRF (Verifiable Random Function) for instant, provably fair randomness.

What You'll Build

A complete web3 game with:

  • Smart contract with VRF integration for random AI opponent
  • Ticket-based game economy (0.001 ETH per game)
  • Backend API orchestrating VRF requests and rewards
  • Realtime event watching with 5ms polling

Note on Architecture: This tutorial uses a backend API to demonstrate VRF request/fulfillment patterns and event watching. For simpler games, you could skip the backend entirely and use RISE Wallet session keys to let users submit transactions directly from the frontend without popups. We're using the backend here specifically to showcase VRF integration patterns.

What You'll Learn

  • How to integrate RISE VRF in Solidity contracts
  • Building VRF consumer contracts with proper callbacks
  • Handling VRF request/fulfillment flow
  • Event watching with viem
  • RISE Wallet integration

Game Flow

  1. Player buys tickets (0.001 ETH each) via RISE Wallet
  2. Player makes choice (rock/paper/scissors)
  3. Backend requests VRF from smart contract
  4. VRF returns random number in 3-5ms
  5. Contract emits result (0=rock, 1=paper, 2=scissors)
  6. Backend watches event, determines winner
  7. Winner gets reward (0.002 ETH) automatically

Prerequisites

Before starting, make sure you have:

  • Node.js 18+ installed
  • Basic knowledge of Solidity and React
  • Foundry installed (getfoundry.sh)
  • A burner wallet private key for the backend sponsor
  • Some testnet ETH (get from RISE Faucet)

This tutorial uses a backend sponsor wallet to pay for VRF requests on behalf of users. The private key is stored in .env.local (gitignored). Never use real funds with exposed keys!

Source Code

The complete source code for this project is available on GitHub: awesamarth/vrf-rps