Skip to content

Latest commit

ย 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Game Guess - IOTA Blockchain dApp

A decentralized number guessing game built on the IOTA blockchain network. Players need to guess 4 secret numbers correctly to receive a Flag NFT.

image

Contract Address

  • Network: testnet
  • Package ID: 0x3062c7a482e441a030860cf496ac40a1d2de08d0938d77154276b033cf985814
  • Explorer: View on Explorer

โœจ Features

  • ๐Ÿ”— Connect IOTA wallet via IOTA dApp Kit
  • ๐ŸŽฏ Submit your guess to the smart contract
  • ๐Ÿ“ฆ Receive GuessBox NFT after each guess
  • ๐Ÿ† Get Flag NFT when guessing correctly
  • โ›“๏ธ Fully on-chain, transparent and immutable
  • ๐ŸŽจ Modern UI with Tailwind CSS

๐Ÿ› ๏ธ Tech Stack

  • Frontend: Next.js 16, React 19, TypeScript
  • Blockchain: IOTA Network (Devnet)
  • Smart Contract: Move Language
  • UI: Tailwind CSS, Radix UI
  • Web3: @iota/dapp-kit, @iota/iota-sdk

๐Ÿ“‹ Prerequisites

  • Node.js 18+
  • IOTA CLI installed
  • IOTA wallet (supporting IOTA dApp Kit)
  • IOTA test tokens (for devnet)

๐Ÿš€ Installation

1. Clone and install dependencies

git clone <repository-url>
cd GameGuess
npm install --legacy-peer-deps

Note: Use --legacy-peer-deps to avoid peer dependency conflicts between React 19 and other libraries.

2. Deploy Smart Contract

npm run iota-deploy

After successful deployment, you'll receive a Package ID. Copy this ID!

3. Update configuration

Open lib/config.ts and replace PACKAGE_ID with your Package ID:

export const PACKAGE_ID = "0x..."; // Replace with your Package ID

4. Run the application

npm run dev

Open your browser and visit http://localhost:3000

๐ŸŽฎ How to Play

  1. Connect Wallet: Click "Connect Wallet" and select your IOTA wallet
  2. Enter Guess: Input 4 numbers (each number from 0-255)
  3. Submit Guess: Click "Submit Guess" to send to blockchain
  4. Get GuessBox ID: After successful transaction, you'll receive a GuessBox object ID
  5. Check Result: Enter GuessBox ID and click "Check" to see the result
  6. Receive Flag: If correct, you'll receive a Flag NFT! ๐ŸŽ‰

๐Ÿงฉ Smart Contract

Structure

module game_guess::guess {
    // Struct storing player's guess
    public struct GuessAttempt has store {
        number1: u16,
        number2: u16,
        number3: u16,
        number4: u16,
    }

    // NFT containing the guess
    public struct GuessBox has key, store {
        id: UID,
        guess: GuessAttempt,
    }

    // Reward NFT when guessed correctly
    public struct Flag has key, store {
        id: UID,
        user: address,
        solved_at: u64,
    }
}

Main Functions

submit_guess(number1: u16, number2: u16, number3: u16, number4: u16)

  • Submit your guess with 4 numbers of type u16 (0-65535)
  • Creates a GuessBox NFT containing your guess
  • GuessBox is transferred to your wallet address

check_guess(guessbox: &GuessBox)

  • Checks if the guess is correct by comparing BCS encoding
  • If correct: Creates and transfers Flag NFT to you
  • If incorrect: Transaction fails with error EIncorrectGuess

How It Works

The smart contract uses BCS (Binary Canonical Serialization) for comparison:

  • Your guess is serialized into bytes
  • Compared with the secret hex string: x"0a0014001e002800"
  • Correct answer: [10, 20, 30, 40]

๐Ÿ“ Project Structure

GameGuess/
โ”œโ”€โ”€ app/                          # Next.js App Router
โ”‚   โ”œโ”€โ”€ layout.tsx               # Root layout with providers
โ”‚   โ”œโ”€โ”€ page.tsx                 # Main page - Game UI
โ”‚   โ””โ”€โ”€ globals.css              # Global styles
โ”œโ”€โ”€ components/                   # React components
โ”‚   โ””โ”€โ”€ Provider.tsx             # IOTA providers (QueryClient, WalletProvider)
โ”œโ”€โ”€ contract/                     # Smart contracts
โ”‚   โ””โ”€โ”€ game_guess/
โ”‚       โ”œโ”€โ”€ sources/
โ”‚       โ”‚   โ””โ”€โ”€ game_guess.move  # Move smart contract
โ”‚       โ”œโ”€โ”€ Move.toml            # Move package config
โ”‚       โ””โ”€โ”€ build/               # Compiled contract (auto-generated)
โ”œโ”€โ”€ hooks/                        # Custom React hooks
โ”‚   โ””โ”€โ”€ useContract.ts           # Hook for contract interaction
โ”œโ”€โ”€ lib/                          # Utilities
โ”‚   โ””โ”€โ”€ config.ts                # Configuration (PACKAGE_ID, network, etc.)
โ”œโ”€โ”€ scripts/                      # Scripts
โ”‚   โ”œโ”€โ”€ iota-deploy-wrapper.js   # Contract deployment script
โ”‚   โ””โ”€โ”€ iota-generate-prompt-wrapper.js
โ”œโ”€โ”€ next.config.ts               # Next.js config
โ”œโ”€โ”€ tailwind.config.ts           # Tailwind config
โ””โ”€โ”€ package.json                 # Dependencies

๐Ÿ”ง Available Scripts

# Development
npm run dev          # Run dev server

# Build
npm run build        # Build for production
npm run start        # Run production server

# Smart Contract
npm run iota-deploy  # Deploy contract to IOTA network

# Linting
npm run lint         # Run ESLint

๐Ÿ› Troubleshooting

Error: "Cannot find module @iota/dapp-kit"

npm install --legacy-peer-deps

Error: "Package not deployed" or transaction fails

  • Make sure you've run npm run iota-deploy
  • Check if PACKAGE_ID in lib/config.ts is correct
  • Verify you're connected to the correct network (devnet)

Error: "Insufficient gas" or transaction rejected

Guess is incorrect but you're sure it's right

  • Double-check the answer: 10, 20, 30, 40 (not 7, 13, 42, 99)
  • Make sure the number order is correct
  • Verify the GuessBox ID is accurate

๐Ÿ’ก Hints

The answer consists of 4 special numbers:

  • ๐Ÿ”ข Nice round numbers
  • ๐Ÿ“Š Following an increasing pattern
  • ๐ŸŽฏ Within the range 0-255
  • ๐Ÿ” Encoded as: x"0a0014001e002800"

Answer: [10, 20, 30, 40] ๐Ÿ˜‰

๐Ÿ” Security

  • โœ… Smart contract written in Move - a resource-safe language
  • โœ… Answer is encoded in bytecode, not easily readable
  • โœ… Uses BCS serialization for validation
  • โœ… No backdoors or admin functions
  • โš ๏ธ This is a demo dApp on testnet, not for production use

๐Ÿ“š References

๐Ÿ“ License

MIT License - See LICENSE file for more details

๐Ÿ‘จโ€๐Ÿ’ป Development

This project was created as a demo to learn how to build dApps on the IOTA blockchain.


Have fun playing! ๐ŸŽฎ๐ŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages