A modern web application to check ERC20 token balances on the Ethereum network. Built with Next.js, TypeScript, shadcn/ui, and ethers.js.
- 🌐 Check ERC20 token balances for any Ethereum wallet
- 🔒 Support for popular tokens (USDT, USDC, BNB)
- ✨ Custom token address support
- 🎨 Modern UI with dark mode support
- ⚡ Real-time balance updates
- 🛡️ Type-safe implementation
- 🎯 Error handling and loading states
src/
├── app/
│ ├── api/
│ │ └── token/
│ │ └── balance/
│ │ └── route.ts # API endpoint
│ └── page.tsx # Main page
├── components/
│ └── token-balance/
│ ├── token-balance-form.tsx
│ ├── balance-display.tsx
│ └── loading-skeleton.tsx
├── constants/
│ └── tokens.ts
├── hooks/
│ └── use-token-balance.ts
└── types/
└── token.ts
- Node.js 16.x or later
- npm or yarn
- Alchemy API key or any Ethereum node provider
- Create a
.env.local
file in the root directory:
# Ethereum RPC URL (Required)
ETHEREUM_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/your-api-key
# Optional configurations
NEXT_PUBLIC_DEFAULT_CHAIN_ID=1
NEXT_PUBLIC_APP_URL=http://localhost:3000
- Clone the repository:
git clone https://github.com/yourusername/token-balance-checker.git
cd token-balance-checker
- Install dependencies:
npm install
# or
yarn install
- Run the development server:
npm run dev
# or
yarn dev
- Open http://localhost:3000 in your browser.
Fetches the balance of an ERC20 token for a specific wallet address.
Parameter | Type | Description | Required |
---|---|---|---|
walletAddress | string | Ethereum wallet address | Yes |
tokenAddress | string | ERC20 token contract address | Yes |
interface TokenBalanceResponse {
success: boolean;
data?: {
walletAddress: string;
tokenAddress: string;
balance: string;
symbol: string;
};
error?: string;
}
curl "http://localhost:3000/api/token/balance?walletAddress=0x123...&tokenAddress=0x456..."
{
"success": true,
"data": {
"walletAddress": "0x123...",
"tokenAddress": "0x456...",
"balance": "1000.50",
"symbol": "USDT"
}
}
Main form component for inputting wallet and token addresses.
interface TokenBalanceFormProps {
onSubmit: (walletAddress: string, tokenAddress: string) => void;
loading: boolean;
}
Component to display token balance information.
interface BalanceDisplayProps {
data: TokenBalanceData;
}
The application implements comprehensive error handling:
- Invalid addresses
- Network errors
- Contract interaction failures
- Rate limiting
- Invalid response formats
- Input validation using ethers.js address validation
- Rate limiting on API routes
- Error message sanitization
- Environment variable protection
- Uses TypeScript for type safety
- Follows ESLint configuration
- Prettier for code formatting
# Run development server
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Run linting
npm run lint
# Run type checking
npm run type-check
- Build the application:
npm run build
- Set up environment variables on your hosting platform
- Deploy the application
- Vercel (recommended)
- Netlify
- AWS Amplify