GitHub - btahir/nickeljoke: A nickel a joke

3 min read Original article โ†—

NickelJoke - Pay a Nickel to Get a Joke Using x402 Micropayments

Screenshot of the app

NickelJoke is a web application that generates personalized jokes on any topic using AI, powered by the x402 payment protocol. Pay small amounts of USDC to get custom jokes, demonstrating the future of micropayments for AI services.

Built with Next.js, x402, and Coinbase CDP, this app showcases how easy it is to monetize AI services with cryptocurrency payments in a fun, engaging way.

This project was built using the x402 AI Starter Kit - a Next.js template that demonstrates how to integrate x402 payments with AI services.

โœจ Features

  • ๐ŸŽญ AI-Powered Jokes - Generate custom jokes on any topic using advanced AI
  • ๐Ÿ’ฐ Micropayments - Pay small amounts of USDC using the x402 protocol
  • ๐ŸŽฒ Smart Suggestions - Get random topic ideas for instant inspiration
  • ๐Ÿ“ฑ Mobile-First - Beautiful, responsive design with smooth animations
  • ๐ŸŽจ Interactive Experience - Scratch-to-reveal joke cards with satisfying animations
  • ๐Ÿ“ค Social Sharing - Share your favorite jokes with unique, shareable links
  • ๐ŸŽ‰ Delightful UX - Confetti animations and engaging visual feedback
  • ๐Ÿ”— Easy Wallet Connection - Seamless Base network integration

๐Ÿ› ๏ธ Tech Stack

๐Ÿš€ Getting Started

git clone https://github.com/btahir/nickeljoke
cd nickeljoke
pnpm install

๐Ÿƒโ€โ™‚๏ธ Running Locally

  1. Set up Coinbase CDP credentials

    Sign into the Coinbase CDP portal and create API keys.

  2. Configure environment variables

    Copy .env.example to .env.local and set:

    • CDP_API_KEY_ID - Your CDP API key ID
    • CDP_API_KEY_SECRET - Your CDP API secret
    • CDP_WALLET_SECRET - Your wallet secret phrase
  3. Start the development server

  4. Open the app

    Visit http://localhost:3000 in your browser.

๐ŸŽฏ How to Use

  1. Connect your wallet using the header button
  2. Switch to Base Sepolia (testnet) if prompted
  3. Enter a joke topic or click "Random Topic" for suggestions
  4. Generate a joke - this will cost a small amount of USDC
  5. Scratch to reveal your personalized joke
  6. Share your joke with the share button

๐Ÿงช Testing Payments

The app uses Base Sepolia (testnet) by default, so you can test with fake money. Get free testnet USDC from the Coinbase CDP faucet.

๐Ÿš€ Deployment

Deploy to Vercel

  1. Push your code to GitHub
  2. Connect to Vercel and deploy
  3. Add environment variables in your Vercel project settings:
    • CDP_API_KEY_ID
    • CDP_API_KEY_SECRET
    • CDP_WALLET_SECRET

Production Setup

To use mainnet (real money):

  1. Set NETWORK=base in your environment variables
  2. Ensure your CDP wallet has sufficient USDC for joke generation costs
  3. Monitor usage through the Coinbase CDP dashboard

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ app/                    # Next.js App Router
โ”‚   โ”œโ”€โ”€ api/joke/          # Joke generation API endpoint
โ”‚   โ””โ”€โ”€ share/[id]/        # Shared joke pages
โ”œโ”€โ”€ components/            # React components
โ”‚   โ”œโ”€โ”€ ui/               # Reusable UI components
โ”‚   โ”œโ”€โ”€ rough-components/ # Hand-drawn style components
โ”‚   โ””โ”€โ”€ joke-*.tsx        # Joke-specific components
โ””โ”€โ”€ lib/                  # Utilities and configuration

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is open source and available under the MIT License.