Skip to content

Latest commit

ย 

History

History
113 lines (83 loc) ยท 2.76 KB

File metadata and controls

113 lines (83 loc) ยท 2.76 KB

๐Ÿ‰ Fruity Slice Token Game on Solana (Devnet)

A fun, blockchain-integrated Fruit Ninja-style game built using React (JSX) and powered by the Solana blockchain. Players slash fruits to earn tokens based on their score. Tokens are distributed from a house wallet through a backend server using a secure claim system.


๐Ÿ“ Tech Stack

  • Frontend: React (JSX)
  • Backend: Node.js (Express via server.js)
  • Blockchain: Solana
  • Token: Custom SPL Token

๐Ÿš€ Features

  • ๐Ÿ‰ Fruit Ninja-style gameplay
  • ๐Ÿ” JWT-secured score submission & token claim
  • ๐Ÿ’ฐ Token rewards based on score tiers
  • ๐Ÿ’ธ Airdrops from a House Wallet
  • ๐ŸŒ Solana Devnet integration

โš™๏ธ Setup Instructions

1. Clone the repository

git clone https://github.com/Anantdadhich/fruityslice.git

2. Install dependencies

npm install

3. Create your .env file

Create a .env file in the root of your project and fill in:

PAYER_WALLET=your_base58_encoded_secret_key
JWT_SECRET=your_jwt_secret
JWT_EXPIRY=1h
AUTH_TOKEN=static_auth_token_if_applicable
VITE_BACKEND=http://localhost:3001

4. Run the Solana setup (Devnet)

Run your wallet/token setup script to generate:

  • โœ… House Wallet Address
  • โœ… Token Mint Address
  • โœ… House Token Account

Save those and update the frontend/backend with:

const TOKEN_MINT = new PublicKey("your_token_mint");
const PAYER = Keypair.fromSecretKey(bs58.decode(process.env.PAYER_WALLET));
const HOUSE_WALLET = PAYER.publicKey;

๐Ÿง  Game Logic (Frontend)

  • The frontend renders the Fruit Ninja game
  • Player score is tracked
  • On game over, players can claim rewards
  • handleClaim() sends the score to the backend, which validates it, calculates rewards, and triggers a token transfer

๐Ÿ›  Backend (server.js)

Handles:

  • โœ… JWT authentication
  • โœ… POST /api/login โ€” returns JWT token
  • โœ… POST /api/transfer-tokens โ€” transfers SPL tokens to playerโ€™s wallet based on score

Uses:

  • @solana/web3.js to interact with Devnet
  • JWT for session security
  • In-memory specialrewardClaimed for limited bonus rewards

๐ŸŽฎ Reward System

export const getSliceReward = (score) => {
  if (score < 10) return 0;
  if (score < 20) return 0.005 * LAMPORTS_PER_SOL;
  if (score < 50) return 0.01 * LAMPORTS_PER_SOL;
  if (score < 100) return 0.03 * LAMPORTS_PER_SOL;
  return 0.05 * LAMPORTS_PER_SOL;
};

๐Ÿ’ก Notes

  • Everything runs on Solana Devnet, no real SOL involved.
  • Make sure to fund your house wallet with devnet SOL using:
solana airdrop 2 <house_wallet_address> --url devnet

๐Ÿ“ฉ Contact

Made by Anant โ€” Full Stack Developer experimenting with blockchain gaming on Solana.

Feel free to reach out or contribute!