Skip to content

Timi16/answer-chain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AnswerChain

A course-specific, blockchain-powered Q&A platform for Nigerian university students. AnswerChain fixes unstructured peer learning on WhatsApp/Telegram and the lack of syllabus-aligned help on global forums by adding curriculum context, stake-based incentives, and verifiable on-chain rewards.


✨ Description

AnswerChain introduces ANSWRβ€”a native utility token that fuels the ecosystem.

  • New users receive a starter bundle of ANSWR on registration.
  • Posting a question reserves a small token fee as a reward pool.
  • Students answer and upvote; top answers share the reward pool.
  • Optional bounties attract higher-quality solutions.
  • Earned tokens can be redeemed via Solana Pay or exchanged for platform merchandise.
  • The result: a learn-to-earn loop that is academically impactful and financially rewarding.

🧭 User Flow

  1. Onboarding
    Register with university email, link a Solana wallet, receive welcome ANSWR tokens.

  2. Ask a Question
    Fill Title, Details, Category (e.g., Mathematics, CS), and up to 5 tags.
    A small posting fee (in ANSWR) is reserved as the reward pool.

  3. Answer & Upvote
    Peers submit answers (comments). Community upvotes surface the best responses.

  4. Reward Distribution
    When the asker accepts the best answer (or after a timeout), the smart contract splits tokens based on upvote weights.

  5. Bounties (Optional)
    The asker can attach extra ANSWR to a question; bounty is locked and paid to the accepted answer.

  6. Redemption
    Redeem earned ANSWR to SOL via Solana Pay (or swap partners), or claim exclusive merch.


🧠 System Logic

  • Token Initialization
    Each new user receives a fixed welcome amount (configurable, anti-sybil checks apply).

  • Question Posting
    A posting fee (configurable) is escrowed in a reward pool smart contract.

  • Answer Evaluation
    Upvotes are weighted (e.g., by reputation, course level, or staking).
    Off-chain scoring (reputation calc) + on-chain settlement (token split).

  • Reward Payouts
    On acceptance or timeout: distribute ANSWR pro-rata using upvote weights; transfer bounty to accepted answerer.

  • Bounty Layer
    Optional bounty locked on chain; released only to the accepted answer or back to asker on dispute/timeout.

  • Scalability
    Tokenomics can power competitions, inter-university leagues, and sponsored challenges with programmatically verifiable results.


🧰 Tech Stack

  • Frontend: React + TypeScript (Vite), Tailwind (optional)
  • Backend API: Node.js + Express + TypeScript
  • Database: MongoDB + Mongoose (questions, comments, profiles, reputation)
  • Blockchain: Solana (Rust programs / Anchor optional)
    • ANSWR: SPL token (mint, escrow vaults, distribution)
    • Solana Pay for redemptions
  • Validation & DX: Zod, ESLint, Prettier
  • CI/CD (optional): GitHub Actions, Docker

πŸ—‚οΈ Monorepo Structure (suggested)

answer-chain/
β”œβ”€ apps/
β”‚  β”œβ”€ web/                   # React + TS frontend
β”‚  └─ api/                   # Express + TS backend
β”œβ”€ onchain/
β”‚  β”œβ”€ programs/              # Rust/Anchor Solana programs
β”‚  └─ scripts/               # IDLs, deployment helpers
β”œβ”€ packages/
β”‚  β”œβ”€ ui/                    # shared UI (optional)
β”‚  └─ types/                 # shared TypeScript types
└─ docs/
   └─ README.md              # this file

πŸ“¦ API Overview

Base URL (local): http://localhost:3000/api

Questions

  • POST /questions β€” Create a question
    Body

    {
      "title": "How do I solve this differential equation with boundary conditions?",
      "details": "What I've tried... Equations... Expected outcome...",
      "category": "Mathematics",
      "tags": ["calculus", "ode"],
      "bounty": 100
    }
  • GET /questions β€” List (query params: q, category, tags, sort, page, limit)

  • GET /questions/:id β€” Get one (includes commentsCount)

  • PATCH /questions/:id β€” Update (title/details/category/tags/bounty/status)

  • DELETE /questions/:id β€” Delete (and cascade delete comments)

  • POST /questions/:id/bounty β€” Set/Increase bounty
    Body

    { "bounty": 250 }
  • PATCH /questions/:id/accept/:commentId β€” Accept a comment as the answer (closes question)

Comments

  • POST /questions/:id/comments β€” Add comment
    Body
    {
      "content": "Separate variables: du/u = k dx ...",
      "parentCommentId": "optional-parent-comment-id"
    }
  • GET /questions/:id/comments β€” List comments (flat; use parentCommentId for threads)
  • PATCH /comments/:commentId β€” Update comment
    Body
    { "content": "Small correction..." }
  • DELETE /comments/:commentId β€” Delete comment

Categories (exact strings): Mathematics, Physics, Computer Science, Chemistry, Biology, Engineering, Medicine, Social Sciences.


🧾 Data Models (simplified)

Question

{
  _id: ObjectId,
  title: string,                    // max 200
  details: string,                  // max 20k
  category: "Mathematics" | ...,
  tags: string[],                   // up to 5
  bounty: number,                   // >= 0
  createdBy: ObjectId,              // User
  acceptedCommentId?: ObjectId,
  status: "open" | "closed",
  createdAt: Date,
  updatedAt: Date
}

Comment

{
  _id: ObjectId,
  question: ObjectId,               // Question
  content: string,                  // max 20k
  createdBy: ObjectId,              // User
  parentCommentId?: ObjectId,       // for threads
  createdAt: Date,
  updatedAt: Date
}

πŸͺ™ Tokenomics (configurable)

  • Welcome Grant: WELCOME_TOKENS per verified student.
  • Posting Fee: POST_COST_TOKENS escrowed to reward pool.
  • Upvote Weights:
    weight = base + rep_factor(reputation) + course_factor(level) + stake_factor(stakedANSWR)
  • Payout Split: Pro-rata by upvote weight; bounty 100% to accepted answerer.
  • Redemption: Solana Pay (convert ANSWRβ†’SOL) or merch claims.

On-chain: SPL mint for ANSWR, escrow PDAs for per-question pools, distribution instruction invoked by backend oracle or client after acceptance/timeout.


πŸ—οΈ On-Chain Architecture (Solana)

  • Programs
    • ANSWR Mint: SPL token (existing mint address).
    • Escrow Program:
      • create_pool(question_id, poster_pubkey, amount)
      • fund_bounty(question_id, asker_pubkey, amount)
      • settle(question_id, accounts[], split[]) (verifies signatures; distributes)
      • refund_if_timeout(question_id) (optional governance)
  • PDAs
    • RewardPoolPDA(question_id) holds escrowed ANSWR.
  • Guards
    • University email verification β†’ wallet gate
    • Anti-sybil rate limits (per IP/semester)
    • Program checks: signer, question status, distribution sum = pool + bounty

πŸ§ͺ Local Development

Prerequisites

  • Node.js 18+, pnpm/npm
  • MongoDB (local or Atlas)
  • Solana CLI + local validator (optional for on-chain testing)
  • Rust + Anchor (if using Anchor)

Backend (API)

cd apps/api
cp .env.example .env
# Edit .env: MONGODB_URI, PORT=3000, SOLANA_RPC_URL, ANSWR_MINT, etc.

pnpm install
pnpm dev         # runs nodemon on http://localhost:3000

Environment (.env)

PORT=3000
MONGODB_URI=mongodb://localhost:27017/answerchain
SOLANA_RPC_URL=https://api.devnet.solana.com
ANSWR_MINT=YourSplMintAddress
WELCOME_TOKENS=100
POST_COST_TOKENS=5
JWT_SECRET=dev-only-use-real-secret

Frontend (Web)

cd apps/web
cp .env.example .env
# VITE_API_BASE_URL should match API: http://localhost:3000/api
pnpm install
pnpm dev         # http://localhost:5173 (default Vite port)

Frontend env (.env)

VITE_API_BASE_URL=http://localhost:3000/api

πŸ§ͺ Quick Postman Tests

Base: http://localhost:3000/api

  1. Create question
POST /questions
{
  "title": "Big-O of nested loops with varying ranges?",
  "details": "I tried amortized analysis... need clarity on inner loop bounds.",
  "category": "Computer Science",
  "tags": ["algorithms","big-o"],
  "bounty": 50
}
  1. Add comment
POST /questions/:id/comments
{
  "content": "Outer loop N, inner averages to N/2 β†’ O(N^2)."
}
  1. Accept answer
    PATCH /questions/:id/accept/:commentId

  2. List questions
    GET /questions?category=Computer%20Science&sort=bounty&page=1&limit=10


πŸ”’ Security Notes

  • Auth: JWT/session recommended; rate limit writes (questions, comments, upvotes).
  • Validation: All payloads validated with Zod on the server.
  • Abuse Mitigation:
    • University email domain whitelisting
    • Device/browser fingerprint (light)
    • Treasury/bounty timelocks + allowlist programs for settlement
  • Secrets: Never commit private keys; use KMS or key managers for settlement oracles (if any).

🧱 Roadmap

  • MVP: Q&A + bounties + Solana payouts
  • Reputation: Per-course reputation affecting upvote weight
  • Courses/Faculties: Per-school/department gating, course codes (e.g., MAT 201)
  • Events: Inter-university contests, sponsored challenges
  • Moderation: Flagging, plagiarism detection, LLM-assisted triage
  • Mobile: PWA first; native app later
  • DAO/Grants: Governance for token parameters and sponsorship pools

🀝 Contributing

  1. Fork & create a feature branch.
  2. Follow coding standards (ESLint/Prettier; pnpm lint).
  3. Write minimal tests for business logic.
  4. Open a PR with a clear description and screenshots (if UI).

πŸ“š FAQ

Why Solana?
Low fees, high throughput, mature SPL ecosystem, Solana Pay support.

Is ANSWR transferrable?
Yes (SPL token). Transfers may be restricted per compliance during alpha.

How do payouts work?
On acceptance/timeout, the program splits ANSWR; students redeem to SOL via Solana Pay or exchange merch credits.

Can I use it without tokens?
Read-only browsing is free; posting/answering uses small token amounts (to curb spam and reward quality).


πŸ“ License

MIT β€” see LICENSE for details.



AnswerChain turns everyday coursework into a verifiable, rewarding, and collaborative learning economyβ€”built in Nigeria, for Nigerian students, on Solana.

About

A Blockchain Qa Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published