Full lesson
snap-solve
A full-stack urban-reporting dApp built on Solana and Next.js that enables users to create and sign incentivized petitions for local community issues.
What it does
From the project README:
Welcome to the SnapSolve project! SnapSolve revolutionizes urban reporting by incentivizing petitions, empowering citizens to report issues such as infrastructure damage, while voters prioritize them for swift action. This decentralized platform rewards both reporters and voters, promoting faster responses and greater transparency. Get rewarded by creating or signing petitions—it's that simple!
- Original
- Eddy3129/snap-solve
- SuperStack fork
- Blockchains/snap-solve @
0231acf - Stars
- 1
- Last push (original)
- 2024-10-10
- Languages
- TypeScript, Rust, CSS, JavaScript
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- GamingConsumer & Social
- Licence
- MIT
- Homepage
- https://snap-solve.vercel.app
Architecture
32 source files. By extension: .tsx ×21, .ts ×8, .js ×2, .rs ×1.
| Top-level directory | Source files |
|---|---|
components | 14 |
app | 7 |
(root) | 4 |
lib | 4 |
petition_program | 3 |
On-chain programs: petition_program/programs/petition_program
Dapp: deploying
This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/snap-solve/, 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.
petition_program/programs/petition_program/src/lib.rs L121–144 @ 0231acf · MIT · original } Ok(()) } } #[derive(Accounts)]pub struct CreatePetition<'info> { #[account( init_if_needed, payer = creator, space = Petition::LEN, seeds = [b"petition", creator.key().as_ref()], bump, )] pub petition: Account<'info, Petition>, #[account(mut)] pub creator: Signer<'info>, pub system_program: Program<'info, System>,} #[derive(Accounts)]pub struct VotePetition<'info> {- Line 131
init_if_needed,: Creates the account only if it doesn't exist. Watch for re-initialisation bugs. - Line 134
seeds = [b"petition", creator.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 135
bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 139
pub creator: Signer<'info>,: Requires this account to have signed the transaction.
components/petition/create-post.tsx L109–132 @ 0231acf · MIT · original if (!anchorWallet) { alert('Wallet not connected'); return; } try { // Initialize Anchor provider const provider = new AnchorProvider(connection, anchorWallet, { preflightCommitment: 'processed', }); setProvider(provider); // Sets the default provider for Anchor // Instantiate Program with correct program ID const programId = new PublicKey("xnvDsEDqnUh22BRpicSSSJHKjKtBJpPa1j1esc8tpww"); const program = new Program(idl as Idl, provider); // Derive the PDA for the petition account using the creator's public key const [petitionPDA, bump] = await PublicKey.findProgramAddressSync( [Buffer.from("petition"), publicKey.toBuffer()], // Use creator's public key for PDA program.programId ); const targetVotesBN = new anchor.BN(targetVotes);- Line 127
const [petitionPDA, bump] = await PublicKey.findProgramAddressSync(: Derives a PDA from seeds and the program ID and returns the address with its canonical bump. - Line 127
const [petitionPDA, bump] = await PublicKey.findProgramAddressSync(: 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 | next dev |
. | npm run start | next start |
. | npm run build | next build |
. | npm run lint | next lint |
petition_program | npm run lint | prettier */*.js "*/**/*{.js,.ts}" --check |
petition_program | anchor build | compile programs and generate IDLs |
petition_program | anchor test | local validator + test suite |
petition_program | 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