A production-ready tip jar dApp built on Stacks (Bitcoin L2) with modular architecture, Farcaster Frame support, and Clarity 4 features.
- ✅ 34-byte memo constants - Fixed from 35 bytes to correct 34 bytes
- ✅ Buffer polyfill - Added vite-plugin-node-polyfills for browser compatibility
- ✅ Network validation - Validates wallet network matches app configuration
- ✅ Transaction timeout - Added 2-minute timeout for pending transactions
- ✅ Post-conditions - Implemented proper STX post-conditions for security
- ✅ Faucet cooldown persistence - Now survives page reloads via localStorage
- ✅ Character counter - Fixed off-by-one error (was allowing 281 chars)
- ✅ History detection - Better detection of contract history support
- ✅ User stats loading - Added premium status and progress tracking
- ✅ Error handling - Comprehensive try-catch blocks throughout
- ✅ Safe localStorage - Wrapped all localStorage calls in error handlers
Use tip-jar-v4.clar - This is the ONLY contract you should deploy. Other versions included for reference only.
- 💸 Accept Tips: Receive STX tips from anyone with on-chain memos
- 💬 Custom Messages: Send tips with UTF-8 messages (Clarity 4)
- 🔐 Secure: Owner-only withdrawal with post-conditions
- 🎨 Modern UI: Clean, responsive design with gradient backgrounds
- 🦊 Multi-Wallet: Support for Leather and Xverse wallets
- 📊 Real-time Stats: Live contract balance and tip tracking
- 📜 Transaction History: Full on-chain transaction history
- 👑 Premium Tippers: Unlock premium status with 10+ STX in tips
- 🔗 Farcaster Ready: Built-in Frame support for social sharing
- ⚡ Lightning Fast: Modular ES6 architecture
- 🛡️ Error Handling: Comprehensive error management
- 📱 Responsive: Works on all devices
stacks-tip-jar/
├── index.html # Main HTML entry point
├── styles.css # Application styles
├── main.js # Application entry point
├── config.js # Configuration and utilities (FIXED)
├── wallet.js # Wallet connection management (FIXED)
├── contract.js # Smart contract interactions
├── ui.js # UI controller and state (FIXED)
├── contracts/
│ └── tip-jar-v4.clar # Clarity 4 contract (FIXED - USE THIS ONE)
├── package.json # Project metadata (FIXED)
├── vite.config.js # Vite config with polyfills (FIXED)
└── README.md # This file (UPDATED)
- A Stacks wallet (Leather or Xverse)
- Node.js 18+ and npm 9+
- Basic knowledge of blockchain and cryptocurrencies
- Clone the repository
git clone https://github.com/CryptoExplor/stacks-tip-jar.git
cd stacks-tip-jar- Install dependencies (IMPORTANT - includes polyfills)
npm install- Deploy the smart contract
- Go to Stacks Explorer Sandbox
- Copy code from
contracts/tip-jar-v4.clar(ONLY use v4!) - Deploy to testnet first for testing
- Save your contract address (starts with ST for testnet)
- Configure your contract
Edit config.js and update:
export const CONFIG = {
CONTRACT: {
ADDRESS: 'ST3ZQXJPR493FCYNAVFX1YSK7EMT6JF909E3SDNQG', // ⚠️ YOUR DEPLOYED ADDRESS
NAME: 'tip-jar-v4', // ⚠️ MUST MATCH DEPLOYED CONTRACT NAME
OWNER: 'ST3ZQXJPR493FCYNAVFX1YSK7EMT6JF909E3SDNQG' // ⚠️ YOUR ADDRESS
},
NETWORK: {
DEFAULT: 'testnet', // Use 'testnet' first, then 'mainnet'
}
// ... rest stays the same
};- Run locally
npm run dev- Build for production
npm run build- Deploy to Vercel
# Install Vercel CLI
npm install -g vercel
# Deploy
vercel --prod- Visit the deployed site
- Click "Connect Wallet" and choose Leather or Xverse
- Approve the connection in your wallet
- Enter a tip amount or use quick amounts
- (Optional) Add a custom message
- Click "Send Tip" and confirm in your wallet
- Transaction complete! 🎉
The contract owner can withdraw accumulated tips:
;; Call from Clarinet or Stacks Explorer
(contract-call? .tip-jar-v4 withdraw 'YOUR-ADDRESS)Change network in config.js:
NETWORK: {
DEFAULT: 'testnet', // or 'mainnet'
}IMPORTANT: Ensure your wallet is on the same network!
Adjust settings in config.js:
UI: {
QUICK_AMOUNTS: [0.1, 0.5, 1, 5],
MIN_TIP: 0.000001,
MAX_TIP: 1000000,
MAX_MESSAGE_LENGTH: 280
}Every tip and withdrawal includes an on-chain memo:
- Tips: "TIP RECEIVED!"
- Withdrawals: "WITHDRAW OK"
Users can attach custom messages to tips:
(send-tip-with-message u1000000 u"Thanks for the content!")Full transaction history stored on-chain:
- Tipper address
- Amount
- Block height
- Message flag
Uses to-consensus-buff? for additional data integrity.
Access full STX account information via stx-account.
send-tip (amount uint)- Send a tip with memosend-tip-with-message (amount uint) (message string-utf8)- Send tip with custom messagewithdraw (recipient principal)- Withdraw tips (owner only)transfer-ownership (new-owner principal)- Transfer ownershipset-premium-threshold (new-threshold uint)- Update premium threshold
get-owner- Get contract ownerget-total-tips- Get total tips receivedget-contract-balance- Get current balanceget-total-tippers- Get unique tipper countget-total-transactions- Get transaction countget-tipper-stats (tipper principal)- Get user statisticsget-transaction (tx-id uint)- Get specific transactionget-tip-message (tipper principal) (tip-id uint)- Get tip messageis-premium-tipper (tipper principal)- Check premium statusget-contract-summary- Get all stats at once
- ✅ Post-conditions on all STX transfers
- ✅ Owner-only withdrawal mechanism
- ✅ Input validation on all transactions
- ✅ Secure wallet connection handling
- ✅ No private key exposure
- ✅ Network validation
- ✅ Transaction timeouts
- ✅ XSS protection headers
Solution: Switch your wallet to match CONFIG.NETWORK.DEFAULT:
- Testnet: Addresses start with ST
- Mainnet: Addresses start with SP
Solution: Check your wallet for a pending approval popup. Timeout is 2 minutes.
Solution: Verify in config.js:
CONTRACT: {
ADDRESS: 'ST...', // ✅ Correct format
NAME: 'tip-jar-v4', // ✅ Must match deployed name
}Solution: Must serve over HTTP, not file://
npm run dev # Use Vite dev serverSolution: Ensure vite-plugin-node-polyfills is installed:
npm install vite-plugin-node-polyfills --save-devPossible causes:
- Contract doesn't support history (not v4)
- No transactions yet (shows "No tips yet")
- Contract call failed (check console)
Solution: Deploy tip-jar-v4.clar which includes full history support.
The modular structure makes it easy:
- New wallet: Extend
WalletManagerinwallet.js - Contract functions: Add to
ContractManagerincontract.js - UI enhancements: Modify
UIControllerinui.js - Configuration: Update
config.js
# Format code (if using Prettier)
npm run format
# Type check (if using TypeScript)
npm run type-check
# Lint (if using ESLint)
npm run lintMIT License - see LICENSE file for details
- Built on Stacks - Bitcoin L2
- Wallet integrations: Leather, Xverse
- API: Hiro Systems
- GitHub Issues: Report a bug
- Twitter: @kumar14700
Built with ❤️ on Stacks • Secured by Bitcoin • Enhanced with Clarity 4
Version: 2.0.1 (All Critical Issues Fixed)
Tip Address: ST3ZQXJPR493FCYNAVFX1YSK7EMT6JF909E3SDNQG