Inspiration

Traditional blockchain marketplaces have a major UX problem: users need to hold native tokens (like MATIC) just to pay for gas fees. This creates friction because new users need to acquire native tokens from exchanges first, manage multiple token balances, and worry about gas price fluctuations.

We wanted to build a marketplace where users can buy and sell products using only stablecoins, without any gas fee concerns.

What it does

Polygon x402 Marketplace is a gasless peer-to-peer marketplace that enables users to buy and sell products using USDC on Polygon Amoy without paying any gas fees. The platform leverages the x402 protocol to handle payments seamlessly, allowing users to trade with just USDC in their wallet - no native tokens (MATIC/POL) required for transactions.

Key features:

  • Gasless USDC Payments: Buy and sell products without needing MATIC for gas fees
  • Product Listings: Sellers can list items with title, description, price, stock quantity, and images
  • Instant Purchases: Buyers can purchase items directly with USDC, with automatic stock management
  • Comments System: Users can leave comments on product listings
  • Wallet Integration: Seamless connection via RainbowKit supporting MetaMask, WalletConnect, and more

How we built it

  1. Set up Next.js 16 with React 19 as the foundation with App Router
  2. Integrated RainbowKit and wagmi for wallet connection supporting multiple providers
  3. Implemented x402 payment flow with custom API routes that return 402 Payment Required responses
  4. Built a facilitator proxy that handles EIP-712 domain details and forwards to PayAI for payment verification
  5. Created the marketplace UI with product listings, detail pages, and a sell modal
  6. Set up PostgreSQL with Drizzle ORM for product and comment storage
  7. Added stock management that decreases inventory after successful purchases

Challenges we ran into

  • x402 Protocol Integration: Implementing the x402 payment flow with proper EIP-712 signing for gasless transactions required careful handling of the payment verification and settlement process
  • Facilitator Proxy: Building a local facilitator proxy that correctly forwards requests to PayAI while maintaining proper CORS headers and payment requirements
  • Chain Switching: Ensuring seamless wallet chain switching to Polygon Amoy when users are connected to different networks
  • Real-time Stock Management: Coordinating stock updates between payment confirmation and database updates to prevent overselling

Accomplishments that we're proud of

  • Successfully implemented gasless USDC payments using the x402 protocol
  • Built a fully functional marketplace with product CRUD operations
  • Created a seamless user experience where users only need USDC to participate
  • Deployed a working demo at https://polygon-x402.vercel.app/

What we learned

  • The x402 protocol provides an elegant solution for gasless payments by using EIP-712 signatures and a facilitator network
  • Proper CORS configuration is critical when handling payment headers across origins
  • Building a seamless UX for blockchain applications requires careful attention to wallet state, chain switching, and error handling
  • Drizzle ORM provides excellent TypeScript integration for database operations

What's next for Polygon x402 Marketplace

  • Mainnet Deployment: Deploy to Polygon Mainnet for real-world usage
  • Order History: Add purchase history and order tracking for buyers and sellers
  • Seller Profiles: Create dedicated seller pages with ratings and reviews
  • Category Filtering: Add product categories and search functionality
  • Multi-token Support: Expand beyond USDC to support other stablecoins
  • Mobile Optimization: Enhance mobile experience with PWA features

Built With

  • nextjs
Share this project:

Updates