๐ฎ Game on Solana: Guess the Number
A simple interactive number guessing game powered by smart contracts on the Solana blockchain. Developed with Rust and the Anchor framework.
This project showcases a minimalist on-chain game built using Anchor on the Solana blockchain. It combines basic game logic with decentralized infrastructure, allowing players to interact with a smart contract that "thinks of" a number โ and challenges them to guess it.
A great demo for:
- Learning how to build interactive dApps on Solana
- Understanding Solana account state & transactions
- Combining game mechanics with blockchain immutability
โ๏ธ Stack
- ๐ฆ Rust (smart contract logic)
- โ Anchor (for building & testing Solana programs)
- ๐งช Local Solana validator for development and simulation
โจ Features
-
On-chain Random Number Generation
- The program stores a secret number within its state (pseudo-random for now).
-
Guess by Transaction
- Users guess the number by sending a transaction with their attempt.
-
Immediate Response
- Program replies whether the guess is too low, too high, or correct.
-
Stateless Client
- All game logic and storage is managed on-chain; the client just sends guesses.
๐ Getting Started
1. ๐ง Start the Local Validator
Launch the Solana test environment locally:
solana-test-validator
2. ๐ ๏ธ Build and Deploy the Program
Compile and deploy the Anchor smart contract:
anchor build && anchor deploy
3. ๐ฎ Play the Game
Send transactions with your guess to the validator. Example:
anchor run guess -- --number 42
This assumes you've set up a client command/script to interact with the program using Anchor CLI or custom JS/TS scripts.
๐ง How It Works
- Upon initialization, the program stores a secret number (randomly generated on start).
- Each guess is a transaction with an integer.
- The program processes the guess and emits a response via logs or account state.
๐ License
This project is open-source and licensed under the MIT License โ feel free to build upon, modify, or expand.