A production-ready, enterprise-grade Web3 decentralized application (DApp) built with Next.js 14, TypeScript, Wagmi v2, and Tailwind CSS. This project demonstrates advanced blockchain interaction patterns and modern React architecture, perfect for developers building the next generation of blockchain applications.
This Web3 DApp starter kit showcases best practices for building scalable, maintainable blockchain applications. It features a clean architecture with custom hooks, comprehensive error handling, multi-chain support, and a beautiful UI built with shadcn/ui components.
Perfect for:
- π Learning Web3 development with modern React patterns
- π Bootstrapping new blockchain projects
- πΌ Portfolio demonstration of senior-level React/TypeScript skills
- ποΈ Understanding enterprise-grade DApp architecture
- Multi-Wallet Support: MetaMask, WalletConnect, Coinbase Wallet, and more
- Persistent Connections: Wallet state persists across page reloads
- Network Switching: One-click network switching with user-friendly prompts
- Connection Status: Real-time connection indicators and account information
- Mainnets: Ethereum, Polygon, Arbitrum, Optimism
- Testnets: Sepolia, Polygon Mumbai, Arbitrum Sepolia, Optimism Sepolia
- Dynamic Chain Switching: Switch between networks seamlessly
- Chain-Specific Configuration: Custom RPC endpoints and block explorers
- Balance Tracking: Real-time native and ERC-20 token balances
- Token Transfers: Send ETH and ERC-20 tokens with transaction monitoring
- Transaction History: Track all wallet transactions with explorer links
- Gas Estimation: Real-time gas price tracking and estimation
- Read Operations: Query contract state with automatic updates
- Write Operations: Execute transactions with confirmation tracking
- Event Listening: Real-time contract event monitoring with notifications
- ABI Management: Organized contract ABIs with TypeScript support
- Modern Design: Built with shadcn/ui and Tailwind CSS v4
- Responsive Layout: Mobile-first design that works on all devices
- Dark Mode Ready: Optimized for both light and dark themes
- Toast Notifications: Real-time feedback for all user actions
- Loading States: Skeleton loaders and spinners for better UX
- Domain-Driven Design: Feature-based folder structure
- Custom Hooks: Reusable Web3 hooks for all blockchain operations
- Type Safety: Comprehensive TypeScript typing throughout
- Error Handling: Centralized error parsing with user-friendly messages
- State Management: Zustand for efficient global state management
- Node.js 18.x or higher
- npm, yarn, or pnpm package manager
- MetaMask or another Web3 wallet browser extension
-
Clone the repository
git clone https://github.com/yourusername/web3-dapp-starter.git cd web3-dapp-starter -
Install dependencies
npm install # or yarn install # or pnpm install
-
Configure environment variables
cp .env.example .env.local
Edit
.env.localwith your configuration:# WalletConnect Project ID (Get from: https://cloud.walletconnect.com) NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id_here # Optional: Alchemy or Infura API Keys for better RPC reliability NEXT_PUBLIC_ALCHEMY_API_KEY=your_alchemy_key NEXT_PUBLIC_INFURA_API_KEY=your_infura_key
-
Run the development server
npm run dev # or yarn dev # or pnpm dev
-
Open your browser
Navigate to http://localhost:3000
-
Connect your wallet
Click "Connect Wallet" and select your preferred wallet provider.
The application uses custom hooks to abstract Web3 logic:
useWallet: Manages wallet connection, disconnection, and network switchinguseTokenBalance: Fetches native and ERC-20 token balancesuseContractWrite: Executes contract write operations with transaction trackinguseEventListener: Listens to contract events in real-timeuseGasEstimation: Estimates gas costs for transactionsuseNFTPortfolio: Manages NFT collections and metadata
components/
βββ web3/ # Web3-specific components
β βββ WalletConnect.tsx # Wallet connection UI
β βββ AccountInfo.tsx # Account details display
β βββ TokenBalances.tsx # Token balance list
β βββ TransferForm.tsx # Token transfer form
β βββ CounterContract.tsx # Smart contract demo
β βββ NetworkSwitcher.tsx # Network selection
β βββ GasTracker.tsx # Gas price display
βββ ui/ # shadcn/ui components
βββ layout/ # Layout components
web3-dapp-starter/
βββ components/ # React components
βββ hooks/ # Custom React hooks
β βββ web3/ # Web3-specific hooks
βββ contracts/ # Contract ABIs and addresses
β βββ abis/ # Contract ABI definitions
βββ lib/ # Utilities and configuration
β βββ web3/ # Web3 configuration
β βββ utils/ # Helper functions
β βββ constants/ # App constants
βββ store/ # State management (Zustand)
βββ types/ # TypeScript type definitions
βββ utils/ # General utilities
βββ styles/ # Global styles and Tailwind config
import { useReadContract } from 'wagmi'
import { COUNTER_ABI, COUNTER_ADDRESS } from '@/contracts/abis/Counter'
function MyComponent() {
const { data: counterValue, isLoading } = useReadContract({
address: COUNTER_ADDRESS,
abi: COUNTER_ABI,
functionName: 'getValue',
})
return <div>Counter: {counterValue?.toString()}</div>
}import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'
import { COUNTER_ABI, COUNTER_ADDRESS } from '@/contracts/abis/Counter'
function MyComponent() {
const { writeContractAsync, data: hash } = useWriteContract()
const { isLoading: isConfirming } = useWaitForTransactionReceipt({ hash })
const handleIncrement = async () => {
await writeContractAsync({
address: COUNTER_ADDRESS,
abi: COUNTER_ABI,
functionName: 'increment',
})
}
return (
<button onClick={handleIncrement} disabled={isConfirming}>
Increment Counter
</button>
)
}import { useWatchContractEvent } from 'wagmi'
import { COUNTER_ABI, COUNTER_ADDRESS } from '@/contracts/abis/Counter'
function MyComponent() {
useWatchContractEvent({
address: COUNTER_ADDRESS,
abi: COUNTER_ABI,
eventName: 'Incremented',
onLogs(logs) {
logs.forEach((log) => {
console.log('Counter incremented!', log.args)
})
},
})
return <div>Listening for events...</div>
}- Next.js 14 - React framework with App Router
- TypeScript - Static type checking
- Tailwind CSS v4 - Utility-first CSS framework
- Wagmi v2 - React hooks for Ethereum
- Viem - TypeScript interface for Ethereum
- WalletConnect - Multi-wallet connectivity
- MetaMask SDK - MetaMask integration
- Coinbase Wallet SDK - Coinbase Wallet support
- shadcn/ui - Beautifully designed components
- Radix UI - Unstyled, accessible components
- Lucide React - Beautiful icon library
- Sonner - Toast notifications
- Zustand - Lightweight state management
- TanStack Query - Data fetching (via Wagmi)
- Code Style: Follow the existing code style and use Prettier for formatting
- TypeScript: Maintain strict type safety throughout
- Commits: Use conventional commit messages
- Testing: Add tests for new features
- Documentation: Update documentation for significant changes
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'feat: add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Wagmi Team - For the excellent React hooks library
- shadcn - For the beautiful UI components
- Vitalik Buterin - For creating Ethereum
- Next.js Team - For the amazing React framework
- GitHub Issues: [Report bugs or request features]
- Email: [email protected]
β If you find this project helpful, please consider giving it a star!
Built with β€οΈ by Fardin Vahdat