# VRF Rock-Paper-Scissors (/docs/cookbook/vrf-rock-paper-scissors)

import { Cards, Card } from 'fumadocs-ui/components/card';
import { Callout } from 'fumadocs-ui/components/callout';

## 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

<Callout type="warning">
  **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.
</Callout>

{/* ![VRF Rock-Paper-Scissors Game](/vrf-rps-demo.png) */}

### 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](https://getfoundry.sh))
* A burner wallet private key for the backend sponsor
* Some testnet ETH (get from [RISE Faucet](https://faucet.testnet.riselabs.xyz))

<Callout type="info">
  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!
</Callout>

### Source Code

The complete source code for this project is available on GitHub: [awesamarth/vrf-rps](https://github.com/awesamarth/vrf-rps)

## Quick Links

<Cards>
  <Card title="Setup" href="/docs/cookbook/vrf-rock-paper-scissors/setup" description="Project setup, dependencies, and configuration" />

  <Card title="Smart Contract" href="/docs/cookbook/vrf-rock-paper-scissors/smart-contract" description="Build and deploy the VRF-powered game contract" />

  <Card title="Backend API" href="/docs/cookbook/vrf-rock-paper-scissors/backend" description="Create the orchestration API with event watching" />

  <Card title="Frontend" href="/docs/cookbook/vrf-rock-paper-scissors/frontend" description="Build the game UI with RISE Wallet" />
</Cards>
