A decentralized chat application built on the Shardeum EVM Testnet (Mezame) blockchain where all messages are permanently stored on-chain. This dApp demonstrates the power of blockchain technology for censorship-resistant, permanent communication.
- π Wallet Connect: MetaMask integration for secure authentication
- π¬ On-Chain Messages: All messages stored permanently on the blockchain
- β±οΈ Anti-Spam Protection: 10-second cooldown between messages per address
- π± Responsive UI: Beautiful, modern interface built with TailwindCSS
- π Pagination: Load older messages with "Load More" functionality
- β‘ Gas Estimation: Real-time gas cost estimates before sending messages
- π¨ Dynamic Avatars: Unique avatars generated from wallet addresses
- π‘οΈ Input Sanitization: Protection against harmful HTML content
- π Message History: View all past messages from the blockchain
- Storage: Messages stored in on-chain array with sender, timestamp, content, and ID
- Anti-Spam: Cooldown mechanism preventing rapid message posting
- Events: Emits events for message posting with full message details
- Pagination: Efficient message retrieval with start/count parameters
- Wallet Integration: MetaMask connection with network detection
- Real-time Updates: Live message loading and cooldown timers
- Responsive Design: Mobile-first approach with TailwindCSS
- Type Safety: Full TypeScript implementation
- Node.js 18+ and npm/yarn
- MetaMask wallet extension
- Shardeum testnet SHM tokens for gas fees
git clone https://github.com/hozi8-web3/shardeum-onchain-chat
cd shardeum-onchain-chat
npm installcp env.example .env.localEdit .env.local and add your configuration:
# Your wallet private key for contract deployment
PRIVATE_KEY=your_private_key_here
# Contract address (update after deployment)
NEXT_PUBLIC_CONTRACT_ADDRESS=0x0000000000000000000000000000000000000000
# Shardeum RPC URL
NEXT_PUBLIC_RPC_URL=https://api-mezame.shardeum.org
# Chain ID
NEXT_PUBLIC_CHAIN_ID=8119
# Explorer URL
NEXT_PUBLIC_EXPLORER_URL=https://explorer-mezame.shardeum.org# Compile contract
npm run compile
# Deploy to Shardeum EVM Testnet (Mezame)
npm run deployImportant: After deployment, update the contract address in:
.env.localcontexts/ChatContext.tsxcomponents/GasEstimate.tsx
npm run devOpen http://localhost:3000 in your browser.
-
Add Shardeum EVM Testnet (Mezame) to MetaMask:
- Network Name: Shardeum EVM Testnet
- RPC URL:
https://api-mezame.shardeum.org - Chain ID:
8119 - Currency Symbol:
SHM - Block Explorer:
https://explorer-mezame.shardeum.org
-
Get testnet SHM tokens from the Shardeum Faucet
After deployment, verify your contract on the explorer:
npm run deployThe deployment script will automatically attempt verification.
- Click "Connect Wallet" button
- Approve MetaMask connection
- Ensure you're on Shardeum EVM Testnet (Mezame) network
- Type your message (max 500 characters)
- View gas cost estimate
- Click "Send" and approve MetaMask transaction
- Wait for blockchain confirmation
- Messages load automatically with newest first
- Use "Load Older Messages" for pagination
- Scroll to bottom button appears when needed
shardtalk/
βββ contracts/ # Smart contracts
β βββ ShardeumChat.sol
β βββ ShardeumChat.json
βββ scripts/ # Deployment scripts
β βββ deploy.js
βββ app/ # Next.js app directory
β βββ globals.css
β βββ layout.tsx
β βββ page.tsx
βββ components/ # React components
β βββ ChatInterface.tsx
β βββ MessageInput.tsx
β βββ MessageList.tsx
β βββ MessageItem.tsx
β βββ WalletConnect.tsx
β βββ GasEstimate.tsx
βββ contexts/ # React contexts
β βββ ChatContext.tsx
βββ types/ # TypeScript types
β βββ global.d.ts
βββ hardhat.config.js # Hardhat configuration
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run compile # Compile smart contracts
npm run deploy # Deploy to Shardeum
npm run test # Run Hardhat testspostMessage(string content): Send a new messagegetMessages(uint start, uint count): Retrieve paginated messagesgetTotalMessageCount(): Get total number of messagesgetCooldownRemaining(address user): Check user's cooldown status
NEXT_PUBLIC_CONTRACT_ADDRESS=your_deployed_contract_address
NEXT_PUBLIC_RPC_URL=https://api-mezame.shardeum.org
NEXT_PUBLIC_CHAIN_ID=8119
NEXT_PUBLIC_EXPLORER_URL=https://explorer-mezame.shardeum.org- Input Sanitization: HTML entities escaped to prevent XSS
- Anti-Spam: Rate limiting per wallet address
- Gas Estimation: Transparent cost display
- Wallet Validation: Network and balance checks
- Error Handling: Graceful failure handling
npm run testnpm run lint
npm run buildTypical gas costs on Shardeum EVM Testnet (Mezame):
- Message Posting: ~50,000 gas
- Gas Price: ~1 Gwei
- Total Cost: ~0.00005 SHM per message
Costs may vary based on network congestion
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Built with β€οΈ for the decentralized future
Join the conversation on the blockchain! π