A modern, full-stack Progressive Web Application built with Next.js 14, featuring Web3 authentication with Privy, camera photo NFT minting, and offline capabilities powered by Serwist.
- πΈ Camera NFT Minting: Capture photos with your camera and mint them as NFTs on Monad testnet
- π Web3 Authentication: Seamless wallet connection and user authentication using Privy
- π IPFS Storage: Decentralized storage for images and metadata via Pinata
- π± Progressive Web App: Full PWA capabilities with offline support via Serwist
- π Push Notifications: Web push notifications for user engagement
- π Dark/Light Mode: Responsive design with theme support
- π± Mobile-First: Optimized for mobile devices with install prompts
- β‘ Modern Stack: Built with Next.js 14, TypeScript, and Tailwind CSS
- Frontend: Next.js 14, React 18, TypeScript
- Styling: Tailwind CSS
- Web3: Privy, Wagmi, Viem, Monad Testnet
- NFT Storage: IPFS via Pinata
- Camera: MediaDevices API, Canvas API
- PWA: Serwist (Service Worker)
- State Management: TanStack Query
- Notifications: Web Push API
Before you begin, ensure you have the following:
- Node.js (v18 or higher)
- npm or yarn
- A Privy account and App ID from privy.io
- A Pinata account and JWT token from pinata.cloud
- MON tokens for gas fees on Monad testnet
- A device with camera access (for NFT minting)
git clone https://github.com/monad-developers/next-serwist-privy-camera-nft
cd next-serwist-privy-camera-nft
npm install
Create a .env.local
file in the root directory:
# Option 1: Copy from example (if .env.example exists)
cp .env.example .env.local
# Option 2: Create manually
touch .env.local
Add the following environment variables to your .env.local
file:
#Β Privy
NEXT_PUBLIC_PRIVY_APP_ID=your_privy_app_id_here
NEXT_PUBLIC_PRIVY_CLIENT_ID= # optional, you can leave this empty
# Web Push
WEB_PUSH_EMAIL=user@example.com
WEB_PUSH_PRIVATE_KEY=your_vapid_private_key
NEXT_PUBLIC_WEB_PUSH_PUBLIC_KEY=your_vapid_public_key
# Pinata Configuration (Required for IPFS - get from Pinata Dashboard)
PINATA_JWT=your_pinata_jwt_token_here
# NFT Contract Configuration (Required after deployment)
NEXT_PUBLIC_NFT_CONTRACT_ADDRESS=your_deployed_contract_address_her
Important: Replace all placeholder values with your actual credentials. Follow the steps below to obtain these values before running the application.
Generate VAPID keys for web push notifications:
npx web-push generate-vapid-keys --json
Copy the generated keys to your .env.local
file.
- Visit privy.io and create an account
- Create a new app, choose Web as the Platform and create the app
- Right after creating the app, copy the App ID
- Add the App ID to your
.env.local
file
- Sign up at Pinata
- Go to API Keys section
- Generate a new JWT token with permissions:
- β pinFileToIPFS (required for uploading files)
- β pinJSONToIPFS (required for uploading metadata)
- Add it to your
.env.local
file asPINATA_JWT
Deploy the provided contracts/PhotoNFT.sol
contract to Monad testnet using Remix IDE or Hardhat/Foundry:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract PhotoNFT is ERC721 {
uint256 private _nextTokenId;
mapping(uint256 => string) private _tokenURIs;
constructor() ERC721("Camera Photo NFT", "PHOTO") {
_nextTokenId = 1;
}
function mint(address to, string memory uri) public {
uint256 tokenId = _nextTokenId++;
_safeMint(to, tokenId);
_tokenURIs[tokenId] = uri;
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
require(_ownerOf(tokenId) != address(0), "Token does not exist");
return _tokenURIs[tokenId];
}
}
Option A: Using Remix IDE
- Go to Remix IDE
- Create a new file and paste the contract code
- Compile the contract (Solidity version
^0.8.19
) - Connect to Monad testnet via MetaMask
- Deploy the contract
- Copy the deployed contract address
Option B: Using Hardhat/Foundry
- Set up a deployment script
- Configure Monad testnet in your config
- Deploy using your preferred tool
After deploying your contract, update the .env.local
file:
NEXT_PUBLIC_NFT_CONTRACT_ADDRESS=0xYourActualContractAddress
npm run dev
The application will be available at http://localhost:3000
.
For full PWA functionality (including install prompts):
npm run build && npm run start
Note: The install app button only works in production mode (
npm run build && npm run start
)
- Desktop: Install button appears in supported browsers
- Mobile: Add to Home Screen prompts on iOS/Android
- Offline: Service worker enables offline functionality
The app includes web push notification capabilities for user engagement and updates.
Important
Enable notifications for the best experience!
To receive push notifications from this app, you need to enable notifications in your browser and/or system settings:
Chrome/Edge:
- Click the lock icon π in the address bar
- Set "Notifications" to "Allow"
- Or go to Settings β Privacy and security β Site Settings β Notifications
Firefox:
- Click the shield icon π‘οΈ in the address bar
- Turn off "Enhanced Tracking Protection" for this site (if needed)
- Allow notifications when prompted
- Or go to Settings β Privacy & Security β Permissions β Notifications
Safari:
- Go to Safari β Settings β Websites β Notifications
- Find your site and set it to "Allow"
macOS:
- System Preferences β Notifications & Focus
- Find your browser and ensure notifications are enabled
- Check "Allow notifications from websites" in browser settings
Windows:
- Settings β System β Notifications & actions
- Ensure your browser can send notifications
- Check browser notification settings
iOS:
- Settings β Notifications β [Your Browser]
- Enable "Allow Notifications"
- Also enable in browser settings
Android:
- Settings β Apps β [Your Browser] β Notifications
- Enable notifications
- Check browser notification permissions
Note
The SendNotification.tsx
component is sample code that requires backend implementation:
- Save subscription data when users subscribe (see TODO comments in code)
- Delete subscription data when users unsubscribe
- Implement
/notification
endpoint to send actual push notifications - Use
web-push
library or similar for server-side notification delivery
To customize your push notification content, edit app/notification/route.ts
and modify the title
, message
, icon
, and other properties in the sendNotification
call.
- Edit the
manifest.json
file - Change the
name
andshort_name
fields - Run
npm run build
to update the app
next-serwist-privy-camera-nft/
βββ app/
β βββ components/ # React components
β β βββ CameraNFT.tsx # Camera NFT minting component
β β βββ InstallPWA.tsx # PWA install prompt
β β βββ UseLoginPrivy.tsx # Privy authentication
β β βββ ...
β βββ api/
β β βββ upload-ipfs/ # IPFS upload API route
β βββ ~offline/ # Offline page
β βββ ...
βββ contracts/
β βββ PhotoNFT.sol # NFT smart contract
βββ public/ # Static assets
βββ ...
- CameraNFT: Complete camera capture and NFT minting functionality
- UseLoginPrivy: Privy authentication integration with Monad testnet
- InstallPWA: PWA installation prompts
- upload-ipfs API: Handles file uploads to IPFS via Pinata
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some 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.
If you encounter any issues or have questions:
- Join Monad Dev Discord
- Review the Privy documentation
- Check the Pinata documentation
- Visit Monad Explorer to view transactions
- Check the Next.js 14 documentation
- Check the Serwist documentation