Solana Decentralized Exchange - Next.JS

Recently Updated
Trending
Solana Decentralized Exchange - Next.JS

Solana Decentralized Exchange – Full Source Code

A production-ready, fully responsive Next.js application for a Solana DEX that uses an aggregator for best-price routing. Launch your own exchange, connect multiple wallets (including Phantom), and earn configurable host fees on every swap.

Key Highlights

  • Full source code with clean, modular Next.js structure.
  • Earn fees via configurable host/referral fee on Solana swaps.
  • Aggregator-powered routing across pools for optimized pricing.
  • Multi-wallet support: Phantom, Solflare, Backpack, Ledger (via Wallet Adapter).
  • Fully responsive UI that works on mobile, tablet, and desktop.
  • Easy setup and 1-click deploy on Vercel.

What You Get

  • Complete Next.js application with pages/components/hooks for swaps and wallet connections.
  • Prebuilt swap flow integrated with a Solana DEX aggregator.
  • Configurable host fee in basis points and payout wallet address.
  • Environment-driven configuration for network, RPC, and aggregator endpoints.
  • TypeScript-first project structure and simple file-based routing.

System Requirements

  • Node.js 18 or newer.
  • npm, yarn, or pnpm.
  • Git.
  • Solana RPC endpoint (HTTPS) for mainnet-beta or devnet.
  • Vercel account for hosting (free tier works).

Environment Variables

  • NEXT_PUBLIC_SOLANA_NETWORK: mainnet-beta or devnet.
  • NEXT_PUBLIC_SOLANA_RPC_URL: HTTPS RPC endpoint URL.
  • NEXT_PUBLIC_AGGREGATOR_API_URL: Base URL for the aggregator API.
  • NEXT_PUBLIC_FEE_BPS: Host fee in basis points (e.g., 10 for 0.10%).
  • NEXT_PUBLIC_FEE_WALLET: Solana address to receive host fees.
  • NEXT_PUBLIC_WALLET_ADAPTERS: Comma-separated list of enabled wallets (e.g., phantom,solflare,backpack,ledger).
  • NEXT_PUBLIC_APP_URL: Public site URL used for callbacks and deep links.

Installation (Local)

  1. Clone the repository and install dependencies.

git clone REPO_URL solana-dex cd solana-dex npm install

  1. Create your environment file.

cp .env.example .env.local

  1. Fill in all required environment variables in .env.local.
  2. Start the development server.

npm run dev

  1. Open http://localhost:3000 and connect a wallet to test swaps.

Buildnpm run build npm start Deploy to Vercel

  1. Push the project to your Git provider.
  2. Import the repository in Vercel.
  3. Set the same environment variables in the Vercel dashboard.
  4. Use the default Next.js build command: next build.
  5. Deploy and verify wallet connections and swap flow on your domain.

How Fees Work

  • Every swap routed through the aggregator can apply a host fee.
  • The fee percentage is controlled by NEXT_PUBLIC_FEE_BPS.
  • Fees are credited to the address in NEXT_PUBLIC_FEE_WALLET.

Supported Wallets

  • Phantom
  • Solflare
  • Backpack
  • Ledger (WebHID/WebUSB where supported)

Responsive Design

The UI adapts to small, medium, and large screens without additional configuration. Navigation, swap forms, and modals are optimized for touch and keyboard input.

Quick Start Checklist

  • RPC endpoint reachable over HTTPS.
  • Fee wallet funded with enough SOL to cover on-chain fees.
  • Aggregator API URL responding from your server location.
  • Environment variables set for both local and Vercel.
  • Wallet adapters enabled for your audience.

Frequently AskedDoes this custody user funds?

No. Users trade directly from their own wallets via on-chain programs routed by the aggregator.

Can I switch networks?

Yes. Set NEXT_PUBLIC_SOLANA_NETWORK to devnet or mainnet-beta and point NEXT_PUBLIC_SOLANA_RPC_URL accordingly.

Can I add or remove wallets?

Yes. Update NEXT_PUBLIC_WALLET_ADAPTERS and the wallet adapter configuration.

Notes

  • Review local regulations for operating an exchange interface.
  • Use at your own risk; always test on devnet before mainnet deployment.

BlockShark's items

Your Code Belongs on Web3

Ship smarter dApps, plug into our marketplace, and grow with the next wave of the internet.