Building a Frontend Interface
Now let's build a web interface for users to interact with our donation contract. The frontend example uses Next.js with NEAR Wallet Selector to create a complete donation experience.
Project Structure
The frontend directory contains a complete Next.js application:
Loading...
Configuration
Configure your contract address and network settings:
Loading...
Wallet Integration
The app supports multiple wallet types through NEAR Wallet Selector:
Loading...
Complete wallet configuration with all supported wallet types:
Loading...
Donation Form Component
The donation form allows users to select preset amounts or enter custom donations:
Loading...
The form includes USD-to-NEAR conversion using CoinGecko API:
Loading...
Handling Donation Transactions
The submit handler processes donations and updates the UI:
Loading...
Displaying Donation History
The donations table shows all contributions with pagination:
Loading...
The component handles pagination and fetches donation data:
Loading...
User's Personal Donations
Track and display the current user's total donations:
Loading...
Navigation Component
Provide wallet connection functionality:
Loading...
Main Page Layout
The home page combines all components:
Loading...
Donation Box Component
The donation box handles wallet connection states:
Loading...
Running the Frontend
Start the development server:
cd frontend
yarn install
yarn dev
Visit http://localhost:3000 to see your donation interface.
Key Frontend Features
Multi-Wallet Support: Supports NEAR native wallets and Ethereum wallets through Chain Abstraction.
Real-time Price Conversion: Converts USD amounts to NEAR using live price feeds.
Transaction Handling: Graceful error handling and transaction state management.
Responsive Design: Mobile-friendly interface using Bootstrap.
Pagination: Efficient handling of large donation lists.
Production Deployment
The frontend is configured for GitHub Pages deployment:
Loading...
Deploy with GitHub Actions:
Loading...
Styling
The application uses Bootstrap for consistent styling:
Loading...
Testing the Interface
Test the complete user flow:
- Wallet Connection: Try different wallet types from the selector
- Donation Flow: Test preset amounts and custom donations
- Price Conversion: Verify USD-to-NEAR conversion accuracy
- Transaction States: Test loading, success, and error states
- Data Updates: Confirm donation tables update after transactions
- Mobile Experience: Test responsive design on various devices
Live Demo
The frontend is deployed and available at:
- Live Demo: https://near-examples.github.io/donation-examples/
- Contract:
donation.near-examples.testnet
Next Steps
With your complete donation application, you can extend it with:
- Donation Goals: Set funding targets and progress tracking
- Donor Recognition: Leaderboards and achievement systems
- Recurring Donations: Subscription-based giving
- Multi-Currency: Support for NEAR fungible tokens
- Analytics Dashboard: Detailed donation metrics and insights
- Mobile App: React Native version for mobile users
This donation pattern serves as a foundation for crowdfunding platforms, tip jars, charity applications, and many other token-handling use cases on NEAR.