Skip to content

ANYTECHS/Token-snatcher-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 

Repository files navigation

Token-snatcher-contracts

Token Snatcher (Whack-to-Earn)

A decentralized arcade game where players โ€œsnatchโ€ tokens before they disappear and earn real on-chain rewards.

This project demonstrates:

Skill-based Web3 gaming

Secure score validation

On-chain reward distribution

Transparent leaderboard

NFT-powered multipliers

๐Ÿ“ Project Structure token-snatcher/ โ”‚ โ”œโ”€โ”€ frontend/ โ†’ Next.js game client โ”œโ”€โ”€ backend/ โ†’ NestJS API server โ”œโ”€โ”€ contract/ โ†’ Soroban smart contract โ”‚ โ””โ”€โ”€ README.md ๐Ÿ–ฅ FRONTEND โ€” Next.js ๐Ÿ“Œ Overview

The frontend is responsible for:

Rendering the game UI

Handling player interactions

Connecting wallet

Starting game sessions

Submitting scores

Displaying leaderboard

It does NOT control rewards. All rewards are validated on-chain.

๐Ÿ— Tech Stack

Next.js

TypeScript

Phaser.js (game engine)

Stellar Wallet integration (Freighter compatible)

Tailwind (optional styling)

๐Ÿ“ Folder Structure frontend/ โ”‚ โ”œโ”€โ”€ app/ โ”‚ โ”œโ”€โ”€ page.tsx โ”‚ โ”œโ”€โ”€ leaderboard/ โ”‚ โ”œโ”€โ”€ ranked/ โ”‚ โ””โ”€โ”€ free/ โ”‚ โ”œโ”€โ”€ components/ โ”‚ โ”œโ”€โ”€ GameCanvas.tsx โ”‚ โ”œโ”€โ”€ WalletButton.tsx โ”‚ โ”œโ”€โ”€ ScoreBoard.tsx โ”‚ โ””โ”€โ”€ Leaderboard.tsx โ”‚ โ”œโ”€โ”€ game/ โ”‚ โ”œโ”€โ”€ scenes/ โ”‚ โ”‚ โ”œโ”€โ”€ GameScene.ts โ”‚ โ”‚ โ””โ”€โ”€ ResultScene.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ spawnLogic.ts โ”‚ โ””โ”€โ”€ scoring.ts โ”‚ โ”œโ”€โ”€ services/ โ”‚ โ”œโ”€โ”€ contract.service.ts โ”‚ โ”œโ”€โ”€ wallet.service.ts โ”‚ โ””โ”€โ”€ api.service.ts โ”‚ โ”œโ”€โ”€ utils/ โ”‚ โ””โ”€โ”€ constants.ts โ”‚ โ””โ”€โ”€ package.json ๐ŸŽฎ Game Flow (Ranked Mode)

Player connects wallet

Player clicks โ€œStart Ranked Gameโ€

Frontend calls contract โ†’ start_session()

Contract returns session ID + randomness seed

Game starts using that seed

Player finishes round

Frontend calls โ†’ submit_score()

Smart contract validates score

Reward distributed automatically

โ–ถ Installation cd frontend npm install npm run dev

App runs at:

http://localhost:3000 ๐Ÿ–ฅ BACKEND โ€” NestJS ๐Ÿ“Œ Overview

The backend is optional but recommended.

It handles:

Leaderboard caching

Tournament scheduling

Analytics

Bot detection

Listening to blockchain events

The backend does NOT control rewards.

๐Ÿ— Tech Stack

NestJS

TypeScript

PostgreSQL

Stellar SDK

๐Ÿ“ Folder Structure backend/ โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ modules/ โ”‚ โ”‚ โ”œโ”€โ”€ game/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ game.controller.ts โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ game.service.ts โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ leaderboard/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ leaderboard.controller.ts โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ leaderboard.service.ts โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ tournaments/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ blockchain/ โ”‚ โ”‚ โ”œโ”€โ”€ stellar.service.ts โ”‚ โ”‚ โ””โ”€โ”€ contract.listener.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ database/ โ”‚ โ”‚ โ””โ”€โ”€ entities/ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ main.ts โ”‚ โ””โ”€โ”€ package.json ๐Ÿ” Backend Responsibilities 1๏ธโƒฃ Listen to Smart Contract Events

New session started

Score submitted

Reward paid

2๏ธโƒฃ Cache Leaderboard

Instead of querying blockchain every time.

3๏ธโƒฃ Anti-Bot Monitoring

Detect abnormal play frequency.

โ–ถ Installation cd backend npm install npm run start:dev

Runs at:

http://localhost:4000 ๐Ÿฆ€ SMART CONTRACT โ€” Stellar (Soroban) ๐Ÿ“Œ Overview

The smart contract is the core of the system.

It handles:

Game sessions

Random seed generation

Score validation

Reward distribution

Leaderboard updates

NFT multiplier logic

All financial logic lives here.

๐Ÿ“ Folder Structure contract/ โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ lib.rs โ”‚ โ”œโ”€โ”€ game.rs โ”‚ โ”œโ”€โ”€ rewards.rs โ”‚ โ”œโ”€โ”€ leaderboard.rs โ”‚ โ”œโ”€โ”€ storage.rs โ”‚ โ””โ”€โ”€ errors.rs โ”‚ โ”œโ”€โ”€ tests/ โ”‚ โ”œโ”€โ”€ test_game.rs โ”‚ โ”œโ”€โ”€ test_rewards.rs โ”‚ โ””โ”€โ”€ test_leaderboard.rs โ”‚ โ”œโ”€โ”€ Cargo.toml โ””โ”€โ”€ README.md ๐Ÿ”‘ Core Contract Functions start_session(player: Address) -> u64

submit_score(session_id: u64, score: u32)

claim_reward(session_id: u64)

get_leaderboard() -> Vec ๐Ÿ” Anti-Cheat Mechanism

The contract:

Generates randomness seed

Stores start timestamp

Enforces time limit

Calculates max theoretical score

Rejects impossible values

Prevents duplicate submissions

Frontend scores are verified mathematically.

โ–ถ Build Contract cd contract cargo build --target wasm32-unknown-unknown --release ๐Ÿš€ Deploy to Testnet soroban contract deploy
--wasm target/wasm32-unknown-unknown/release/token_snatcher.wasm
--source your-identity ๐Ÿ”„ How Everything Works Together Player clicks token โ†“ Frontend updates score โ†“ Player submits score โ†“ Contract verifies logic โ†“ Reward distributed โ†“ Backend caches event โ†“ Leaderboard updates

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors