Full lesson
greedypig-solana
What it does
From the project README:
This is an example of an on-chain CRUD dapp. This example is a journal dapp where you can create, read, update, and delete journal entries on the solana blockchain and interact with the solana program via a UI.
- Original
- cjustinobi/greedypig-solana
- SuperStack fork
- Blockchains/greedypig-solana @
c155714 - Stars
- 1
- Last push (original)
- 2024-10-09
- Languages
- TypeScript, Rust, JavaScript, CSS
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- Other
- Licence
- MIT
- Homepage
- https://greedypig-solana.vercel.app
Architecture
53 source files. By extension: .tsx ×35, .ts ×12, .js ×4, .rs ×2.
| Top-level directory | Source files |
|---|---|
web | 44 |
anchor | 7 |
(root) | 2 |
On-chain programs: anchor/programs/journal
Dapp: deploying
This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/greedypig-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/journal/src/lib.rs L241–264 @ c155714 · MIT · original #[derive(Accounts)]#[instruction(title: String, winning_score: u64, staking_amount: u64, apparatus: String, mode: String, max_players: u8)]pub struct CreateGame<'info> { #[account( init, seeds = [title.as_bytes(), owner.key().as_ref()], bump, payer = owner, space = GameAccountState::space(&title, &apparatus, &mode, max_players) )] pub game_account: Account<'info, GameAccountState>, #[account(mut)] pub owner: Signer<'info>, pub system_program: Program<'info, System>,} #[derive(Accounts)]pub struct JoinGame<'info> { #[account(mut)] pub game_account: Account<'info, GameAccountState>, pub player: Signer<'info>,- Line 243
#[instruction(title: String, winning_score: u64, staking_amount: u64, apparatus: String, m: Touches staking state: the amount locked and when it was locked. - Line 246
init,: Creates and pays for a new account. Space and payer must be specified. - Line 247
seeds = [title.as_bytes(), owner.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 248
bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 256
pub owner: Signer<'info>,: Requires this account to have signed the transaction.
anchor/programs/journal/src/lib copy.rs L49–72 @ c155714 · MIT · original Ok(()) }} #[account]pub struct JournalEntryState { pub owner: Pubkey, pub title: String, pub message: String,} #[derive(Accounts)]#[instruction(title: String, message: String)]pub struct CreateEntry<'info> { #[account( init, seeds = [title.as_bytes(), owner.key().as_ref()], bump, payer = owner, space = 8 + 32 + 4 + title.len() + 4 + message.len() )] pub game_entry: Account<'info, JournalEntryState>, #[account(mut)] pub owner: Signer<'info>,- Line 64
init,: Creates and pays for a new account. Space and payer must be specified. - Line 65
seeds = [title.as_bytes(), owner.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 66
bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 72
pub owner: Signer<'info>,: Requires this account to have signed the transaction.
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 | anchor build | compile programs and generate IDLs |
anchor | anchor test | local validator + test suite |
anchor | anchor run test | ../node_modules/.bin/nx run anchor:jest |
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)