A fullstack application that calculates the USD balance of all coins held by a wallet address on the Sui blockchain.
- Frontend: Next.js 16 (App Router), TailwindCSS, TypeScript
- Backend: Next.js API Routes, node-postgres (
pg) - Database: PostgreSQL 16 (Docker)
- Blockchain: Sui Mainnet RPC
npm installdocker compose up -dThis starts a PostgreSQL container and automatically runs the schema + seed SQL files. The database will be seeded with metadata and price history for 4 coins: SUI, wUSDC, DEEP, CETUS.
Create a .env.local file at the project root:
DATABASE_URL=postgresql://dev:dev@localhost:5433/portfolioNote: The Docker container maps to port 5433 to avoid conflicts with any local PostgreSQL on port 5432. If port 5433 is already in use, update both
docker-compose.ymland.env.localaccordingly.
npm run devOpen http://localhost:3000 in your browser.
- Enter a Sui wallet address in the search bar
- View the portfolio: total USD value, coin list with prices, PnL, and price changes
0x200e6f6dd7e974904cab77e52761f8f0e4e27aabe29f44c7b0e272e8e5ecf543
0xdaf1c8ed29d89cd8f217f609bad0a668fa6f158c12000bfa5f93e670c99e24ff
| Parameter | Required | Description |
|---|---|---|
address |
Yes | Sui wallet address (0x + 64 hex chars) |
limit |
No | Max number of coins to return |
Example:
curl "http://localhost:3000/api/v1/portfolio/coins?address=0x200e6f6dd7e974904cab77e52761f8f0e4e27aabe29f44c7b0e272e8e5ecf543"Response:
{
"coins": [
{
"coin_type": "0x2::sui::SUI",
"symbol": "SUI",
"decimals": 9,
"icon_url": "https://hop.ag/tokens/SUI.svg",
"amount": 3.56,
"usd_value": 10.14,
"price": 2.85,
"pnl_today": 0.5,
"price_change_1d": 5.17,
"price_change_7d": 9.62,
"price_change_30d": 16.33
}
],
"total_usd": 10.55
}src/
app/
page.tsx # Main UI page
api/v1/portfolio/coins/route.ts # API endpoint
lib/
types.ts # TypeScript interfaces
db.ts # PostgreSQL connection + queries
sui-rpc.ts # Sui RPC client
portfolio.ts # Business logic (calculations)
components/ # React components
hooks/ # Custom hooks
db/
01-schema.sql # Database schema
02-seed.sql # Seed data