https://sol-coinflip.vercel.app/ -> Runs in devnet Run
The app consists of a vendor and a player.
- Player triggers a coin flip game by selecting side and the amount of SOL to bet.
- Vendor creates a CoinFlip game on-chain and saves the bet of the user and sends the equal amount of SOL to CoinFlip PDA. In this step, vendor generates a random seed to be used in the coin flip.
- When the CoinFlip account is created, user generates a random seed and sends approves the Play transaction by sending the bet amount to CoinFlip PDA.
- Play function will combine the vendor hash, player hash and the current timestamp to flip the coin. This way, not a single participant can influence the result as the seeds are aggregated from different sources.
- CoinFlip account sends the amount to the winner, logs the events and closes the account.
Webapp is generated using Next.js and Solana Wallet Adapter.
- Start the local Solana validator
- Deploy the app to local cluster with
anchor deploy
- Go to the
app
directory and runnpm run install
- Run the app with
VENDOR_SECRET_KEY
env variable. You can use any keypair as the vendor. Example:VENDOR_SECRET_KEY=[12, 232,1231 ...] npm run dev