Skip to content

mukulcodezz/onchain-solana

Repository files navigation

Onchain

Live Demo GitHub stars License: MIT

Solana wallet PnL tracker and token-gated chat

Paste any wallet address for FIFO cost-basis analytics, or sign in to join holder-only chat rooms.

Built with Next.js 16, Solana wallet-adapter, Helius, Jupiter Price API, and Supabase.

Repository github.com/mukulcodezz/onchain-solana
Live app onchain-solana.vercel.app
License MIT

About

Solana wallet PnL tracker and token-gated chat — decode any Solana wallet's cost basis, realized/unrealized PnL, and allocation across 8 chart types. Connect your wallet to enter token-gated chat rooms verified by on-chain balances.

Tech stack: Next.js 16 · React 19 · TypeScript · Tailwind CSS 4 · Solana wallet-adapter · Helius · Jupiter · Supabase · D3 · Framer Motion

Topics: solana · pnl · portfolio-tracker · nextjs · crypto · web3 · supabase · token-gated


Features

  • Portfolio PnL — FIFO cost basis, realized/unrealized gains, holdings table, flex card export
  • 8 chart types — net worth, allocation ring/treemap, PnL bars, OHLC candles, PnL calendar heatmap, sparklines
  • Token-gated chat — Sign-In With Solana (SIWS), balance-verified room access, live messaging
  • Demo mode — runs without Supabase or Helius using mock data

Quick start

git clone https://github.com/mukulcodezz/onchain-solana.git
cd onchain-solana
npm install
cp .env.example .env.local   # fill in keys (see below)
npm run dev

Open http://localhost:3000.


Environment variables

Copy .env.example to .env.local for local dev. Add the same keys in Vercel → Project → Settings → Environment Variables.

Variable Required Where to get it Used for
SESSION_SECRET Yes (prod) Generate: openssl rand -base64 32 Signs auth session cookies after SIWS
HELIUS_API_KEY Recommended helius.dev → Dashboard → API Keys Token balances, parsed swap history, PnL
NEXT_PUBLIC_RPC_URL Optional Helius RPC URL or any Solana RPC Wallet connection (defaults to public mainnet RPC)
NEXT_PUBLIC_SUPABASE_URL For chat DB supabase.com → Project Settings → API Chat rooms, memberships, messages
NEXT_PUBLIC_SUPABASE_ANON_KEY For chat DB Supabase → Project Settings → API → anon key Client-side Supabase (if used)
SUPABASE_SERVICE_ROLE_KEY For chat DB Supabase → Project Settings → API → service_role key Server-side room/message writes (keep secret)

What works without keys?

Feature No keys Helius only Full stack
Landing page
PnL dashboard Mock data Live PnL Live PnL
Token chat Mock rooms Mock rooms Live chat + gating

API keys setup (step by step)

1. SESSION_SECRET (required for production)

openssl rand -base64 32

Paste into .env.local and Vercel env vars. Without this, auth routes fail in production.

2. Helius (PnL + token gating)

  1. Create account at helius.dev
  2. Create a project → copy API Key
  3. Set HELIUS_API_KEY=your-key
  4. Optional: set NEXT_PUBLIC_RPC_URL=https://mainnet.helius-rpc.com/?api-key=your-key

Helius powers:

  • /api/pnl — wallet balances + transaction history
  • Room join — verifies token gate balances

3. Supabase (chat persistence)

  1. Create project at supabase.com
  2. Run this SQL in SQL Editor:
create table rooms (
  id uuid primary key default gen_random_uuid(),
  name text not null unique,
  gate_mint text not null,
  gate_min numeric not null,
  gate_symbol text,
  created_at timestamptz default now()
);

create table memberships (
  room_id uuid references rooms(id) on delete cascade,
  wallet text not null,
  verified_at timestamptz default now(),
  primary key (room_id, wallet)
);

create table messages (
  id bigserial primary key,
  room_id uuid references rooms(id) on delete cascade,
  wallet text not null,
  content text not null,
  type text default 'text',
  created_at timestamptz default now()
);

create index messages_room_created on messages(room_id, created_at);
  1. Copy from Project Settings → API:
    • NEXT_PUBLIC_SUPABASE_URL
    • NEXT_PUBLIC_SUPABASE_ANON_KEY
    • SUPABASE_SERVICE_ROLE_KEY (server only — never expose to client)

4. Jupiter & CoinGecko (no keys)

Price data uses public endpoints automatically:


Deploy to Vercel

Deploy with Vercel

  1. Push this repo to GitHub
  2. Import in vercel.com/new
  3. Add environment variables from the table above
  4. Deploy

Or via CLI:

npm i -g vercel
vercel login
vercel --prod

Set env vars in the Vercel dashboard before the first production deploy.


Project structure

src/
├── app/
│   ├── api/          # Route handlers (auth, pnl, rooms, prices, flex)
│   ├── chat/         # Token-gated chat UI
│   ├── pnl/          # Portfolio dashboard
│   └── page.tsx      # Landing page
├── components/       # Nav, charts, wallet providers, UI primitives
└── lib/              # Helius, Supabase, PnL engine, SIWS, session

Scripts

Command Description
npm run dev Start dev server
npm run build Production build
npm run lint ESLint
node qa-screenshot.mjs Capture QA screenshots (requires dev server + Playwright)

Security notes

  • Never commit .env.local or service role keys
  • SESSION_SECRET must be set in production (app throws without it)
  • Session cookies are httpOnly, sameSite=strict, and secure in production
  • Chat messages are capped at 2,000 characters; membership is verified before POST

Contributors

Name Role GitHub
👤 mukulcodezz (0xmukul) Author & maintainer @mukulcodezz
🤖 cursoragent (Cursor Agent) AI pair programming @cursoragent

Releases

Version history is published on GitHub Releases.

Version Notes
v0.1.0 Initial public release — PnL dashboard, token-gated chat, demo mode

License

MIT — see LICENSE.