Skip to content

dolphinder/coinflip-pvp

 
 

Repository files navigation

Sui Coin Flip dApp

This is a decentralized PvP (Player vs. Player) coin flip game built on the Sui blockchain. Players can create new games by placing a bet, and other players can join these games to compete for the pot.

Demo on Netlify

Website: https://coinflip-pvp.netlify.app/

Features

  • Decentralized Gameplay: All game logic is handled by a Sui smart contract, ensuring fairness and transparency.
  • Player vs. Player: Create a game or join an existing one to play against others.
  • SUI Betting: Use SUI tokens to place bets.
  • Asynchronous Prize Claiming: Winners receive a PrizeVault token, which they can use to claim their winnings at any time.
  • Built with Next.js: A modern, performant web application built with React and Next.js.

The Game Workflow

The coin flip game has a simple and clear workflow:

  1. Create a Game: A player can start a new game by specifying a bet amount in SUI. This action deploys a Game object on the Sui network, making it available for other players to join.
  2. Join a Game: Another player can browse the list of available games and join one by matching the original player's bet.
  3. The Flip: When a second player joins, the smart contract's flip function is executed.
    • A winner is determined pseudo-randomly using the transaction's digest.
    • A small house fee (1%) is deducted from the total pot.
    • The remaining amount is placed into a PrizeVault.
    • The PrizeVault is transferred to the winner.
  4. Claim Your Prize: The winner can navigate to the "Pending Rewards" section of the dApp and execute a transaction to claim the SUI from their PrizeVault.

Smart Contract

The core logic is powered by a Sui smart contract written in Move. You can find the source code in contracts/coin_flip/sources/coin_flip.move.

Key Functions:

  • create_game: Initializes a new game session.
  • flip: Pits two players against each other and determines a winner.
  • claim_prize: Allows the winner to withdraw their earnings.

Getting Started

First, you need to have the Sui wallet extension installed in your browser and have some SUI tokens on the Testnet.

Then, run the development server:

npm run dev

Open http://localhost:3000 with your browser to see the result.

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

About

This is a decentralized PvP (Player vs. Player) coin flip game built on the Sui blockchain. Players can create new games by placing a bet, and other players can join these games to compete for the pot.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 89.7%
  • CSS 5.8%
  • Move 3.9%
  • JavaScript 0.6%