A simple coin flip game built on Solana Devnet using Next.js and thirdweb's Solana Server Wallet and Transaction API.
This project leverages thirdweb's Solana Server Wallet API for secure server-side wallet management and thirdweb's Solana Transaction API for on-chain transactions. All wallet operations and fund transfers are handled through thirdweb's infrastructure.
- Solana Server Wallet API - Creates and manages Solana wallets server-side
- Solana Transaction API - Handles all on-chain transactions (sending/receiving SOL)
- thirdweb In-App Wallet - User authentication via email/OTP
- Balance API - Real-time wallet balance queries
- User authentication with thirdweb in-app wallet (email/OTP)
- Server-side Solana wallet creation via thirdweb API
- On-chain transactions via thirdweb Transaction API
- Coin flip game using Solana slot hash for randomness
- Automatic fund transfers based on game results
- Install dependencies:
npm install- Set up environment variables in
.env.local:
NEXT_PUBLIC_thirdweb_CLIENT_ID=your_thirdweb_client_id
thirdweb_API_KEY=your_thirdweb_secret_key
NEXT_PUBLIC_SOLANA_NETWORK=devnet
-
Get your thirdweb credentials:
- Go to thirdweb Dashboard
- Create a new project or use existing one
- Get your Client ID (for authentication)
- Get your Secret Key (for API calls)
-
Run the development server:
npm run dev- Open http://localhost:3000 in your browser
- User signs in with email via thirdweb in-app wallet (receives OTP code)
- An EVM wallet is automatically created and connected
- A Solana wallet is created server-side via thirdweb's Server Wallet API using the EVM wallet address as the label
- User selects heads or tails and enters a stake amount
- Coin flip result is determined using the latest Solana slot hash (enhanced with timestamp and address randomness)
- All transactions are processed via thirdweb's Transaction API:
- If user wins: treasury wallet sends 2x stake to user's Solana wallet
- If user loses: user's Solana wallet sends stake to treasury wallet
- UI updates with result and new balances (fetched via thirdweb's Balance API)
- All transactions happen on Solana Devnet
- All wallet operations use thirdweb's Server Wallet API - wallets are created and managed server-side
- All transactions use thirdweb's Transaction API (
/solana/sendendpoint) - Treasury wallet address:
GL4PXGcmYPjpUsNg7RYqxwCypggnq3smfXwjZx2ktP5i - Make sure your treasury wallet has enough SOL for payouts
- The game uses Solana's blockhash (enhanced with timestamp and address randomness) for provably fair randomness
- EVM wallet address is used as the unique identifier for each user
POST /v1/solana/wallets- Create server-side Solana walletsGET /v1/solana/wallets/{address}/balance- Get wallet balancePOST /v1/solana/send- Send SOL transactionsGET /v1/solana/wallets?label={label}- Query wallets by label