Example Apps
Token Swap
Build a token swap dApp on Nexus
Example Token Swap on Nexus
To learn how to build a decentralized exchange (DEX) application on Nexus, take a look at the demo project below:
- Web URL: nexus-swap-example.vercel.app
- GitHub: github.com/nexus-xyz/nexus-swap-example
Overview
This project demonstrates how to build a simple token swap application on the Nexus blockchain. Users can swap Token A for Token B in a 1:1 ratio, showcasing essential DeFi interactions like:
- Token approvals and transfers
- Wallet connection
- Multi-step transactions
- Balance updates
- Event handling
The Smart Contracts
The project uses three main smart contracts:
- Token A Contract:
- Token B Contract:
- Token Swap Contract:
Project Structure
The project is organized into two main packages:
contracts
: A Hardhat project containing the ERC20 token contracts and swap contractfrontend
: A Next.js project with a clean UI for token swapping
Key Features
Smart Contract Architecture
- Uses OpenZeppelin’s ERC20 implementation for tokens
- Simple 1:1 swap mechanism between Token A and Token B
- Two-step approval and swap process for security
Frontend Implementation
- Clean, minimal UI built with Next.js 14 and Tailwind CSS
- Real-time balance updates
- Wallet connection handling
- Transaction status feedback
- Error handling and user notifications
DeFi Concepts Demonstrated
- Token allowances and approvals
- Multi-step DeFi transactions
- Balance tracking
- Contract interactions
- Event monitoring
Getting Started
- Clone the repository and install dependencies:
- Deploy the contracts:
- Start the frontend:
Using the dApp
- Connect your wallet using the “Connect Wallet” button
- View your Token A and Token B balances
- Enter the amount of Token A you want to swap
- Click “Swap” and approve the token spending
- Confirm the swap transaction
- Wait for confirmation and see your updated balances
The contracts are deployed at:
- TokenA:
0x83FD4F92926AC4FB7a0b510aD5615Fe76e588cF8
- TokenB:
0x67bae4B1E5528Fb6C92E7E0BC243341dc71330db
- TokenSwap:
0xf18529580694Ff80e836132875a52505124358EC