Orakl Network
  • Developer's Guide
    • Introduction
    • Verifiable Randomness Function (VRF)
    • Request-Response
    • Data Feed
    • Proof of Reserve
    • Prepayment
    • L2 Services
    • Data Availability Layer API (DAL)
    • Example Projects
      • Binary Option Example
      • Flipcoin Example
      • Mystery Box Example
  • Node Operator's Guide
    • Introduction
    • Orakl Network API
    • Orakl Network CLI
      • Chain
      • Service
      • Listener
      • VRF Keys
      • Reporter
      • Fetcher
      • Delegator
    • Orakl Network VRF
    • Orakl Network Request-Response
    • Orakl Network Data Feed
    • Orakl Network Delegator
    • Orakl Network Proof of Reserve
  • Other Resources
    • Audit
    • White paper
    • Social Media
    • Terms of Use
Powered by GitBook
On this page
  • Code Repository
  • Game Concept
  • Functionality
  • Parameters Setup
  • Coin Flip Execution
  • Result Processing
  • Claiming Winnings
  • Tax Fee Mechanism
  1. Developer's Guide
  2. Example Projects

Flipcoin Example

PreviousBinary Option ExampleNextMystery Box Example

Last updated 1 year ago

This project focuses on creating a simple "flip-the-coin" game to demonstrate the usage of the Orakl-VRF (Verifiable Random Function) service.

Code Repository

The code for this project is available in . Refer to the readme.md file for detailed instructions on forking the game.

Game Concept

Participants wager an amount and choose either heads or tails in this straightforward game. Successful guesses double the bet, while incorrect guesses result in losing the entire bet.

Functionality

This game utilizes the Orakl Network's VRF service to generate a random result for the coin flip.

Parameters Setup

The constructor initializes all necessary parameters for calling the VRF service:

constructor(
    uint64 accountId,
    address coordinator,
    bytes32 keyHash
) VRFConsumerBase(coordinator) {
    COORDINATOR = IVRFCoordinator(coordinator);
    sAccountId = accountId;
    sKeyHash = keyHash;
}

Coin Flip Execution

The flip() function requests a random number from the VRF to determine the coin flip outcome and records bet details for tracking.

Result Processing

The fulfillRandomWords function processes the result from the Orakl VRF service. Winnings are calculated based on the outcome, and balances are adjusted accordingly.

Claiming Winnings

Players can claim their winnings using the claim() function, which transfers the winning balance to their account.

Tax Fee Mechanism

The contract includes a tax fee mechanism, allowing the owner to set the fee with the setTaxFee function. Additionally, the owner can withdraw funds from the contract balance using the withdraw function.

This project serves as an example of integrating Orakl-VRF into a gaming application, demonstrating its ability to provide secure and verifiable random results.

Flip Coin Orakl