Full lesson
poker_solana
Gathering the tight knit community of poker players through a quiz about a player poker hand strength. Competing on RADAR hackathon. Check it out at DOMAIN.
What it does
From the project README:
This project is a blockchain-based Texas Holdem Poker Quiz that challenges users to choose between two poker hands and determine which one has a higher chance of winning. The game quiz covers different stages of a poker round: preflop, flop, turn, and river, allowing users to analyze the odds and make decisions based on each stage. User score and address are saved on the Solana blockchain.
- Original
- Parlov12/poker_solana
- SuperStack fork
- Blockchains/poker_solana @
5ad0a81 - Stars
- 0
- Last push (original)
- 2024-10-06
- Languages
- TypeScript, JavaScript, CSS, Rust
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- GamingConsumer & Social
- Licence
- MIT
- Homepage
- https://poker-solana.vercel.app
Architecture
48 source files. By extension: .tsx ×21, .js ×16, .ts ×10, .rs ×1.
| Top-level directory | Source files |
|---|---|
web | 41 |
anchor | 5 |
(root) | 2 |
On-chain programs: anchor/programs/poksol-leaderboard
Dapp: deploying
This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/poker-solana/, once it is deployed and checked on devnet. Until then, run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
anchor/programs/poksol-leaderboard/src/lib.rs L13–36 @ 5ad0a81 · MIT · original pub fn update_score(ctx: Context<UpdateScore>, score: u64) -> Result<()> { let user_score = &mut ctx.accounts.user_score; user_score.user = ctx.accounts.user.key(); user_score.score = score; msg!("Score updated for user: {:?}", user_score.user); Ok(()) }} #[derive(Accounts)]pub struct Initialize {} #[derive(Accounts)]#[instruction(score: u64)]pub struct UpdateScore<'info> { #[account( init_if_needed, payer = user, space = 8 + 32 + 8, seeds = [b"user-score", user.key().as_ref()], bump )] pub user_score: Account<'info, UserScore>,- Line 18
msg!("Score updated for user: {:?}", user_score.user);: Logs to the program log, which is visible in explorers and the test output. - Line 30
init_if_needed,: Creates the account only if it doesn't exist. Watch for re-initialisation bugs. - Line 33
seeds = [b"user-score", user.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 34
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
How to run, build and test
These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.
| Directory | Command | Runs |
|---|---|---|
. | npm run dev | nx serve web |
. | npm run build | nx build web |
anchor | npm run lint | prettier */*.js "*/**/*{.js,.ts}" --check |
anchor | anchor build | compile programs and generate IDLs |
anchor | anchor test | local validator + test suite |
anchor | anchor run test | yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts |
What you could build from it
- Fork the SuperStack copy and extend it within the Gaming gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Compressed NFTs and state compression
- Learn the pattern first: Building and sending transactions from a client