Ping Crossmint Demo
The Ping Crossmint demo is a complete full-stack implementation showing how to integrate Crossmint smart wallets with the x402 payment protocol. It includes both a React client with UI and an Express server with detailed logging.Overview
This demo demonstrates:- React Client: Full UI for wallet creation, deployment, and payment execution
- Express Server: Protected endpoints with x402 middleware and facilitator integration
- Smart Wallets: Crossmint wallet integration with two signer types (API Key and Email OTP)
- Payment Flow: Complete end-to-end payment from user approval to settlement
- Crossmint smart wallet creation and management
- Two authentication methods: API Key (server-side) and Email OTP (client-side)
- Wallet deployment with ERC-6492 pre-deployment support
- Balance checking (ETH and USDC)
- Payment approval UI with detailed transaction info
- Comprehensive logging and debugging tools
Prerequisites
Development Environment
- Node.js 18.17.0 or higher
- npm 9.0.0 or higher
- Git
Crossmint Account
- Create account at https://www.crossmint.com/
- Navigate to Developer Console → API Keys
- Generate two API keys:
- Server API Key (format:
sk_staging_...) - For API key signer - Client API Key (format:
ck_staging_...) - For Email OTP signer
- Server API Key (format:
- Important: Save keys securely - never commit to git
Testnet Tokens
ETH for gas fees (0.01 ETH minimum):- Visit: https://www.alchemy.com/faucets/base-sepolia
- Paste your wallet address
- Request tokens
- Visit: https://faucet.circle.com/
- Select “Base Sepolia” network
- Paste your wallet address
- Request USDC
Setup
1. Clone and Install
2. Configure Server
server/.env
PORT- Server listen port (default: 3100)PAY_TO- Payment recipient address (use your own to receive testnet USDC)NETWORK- Payment settlement network (default: base-sepolia)
3. Start Client
4. Verify Setup
Server Implementation
The server uses x402-express middleware with facilitator integration:server/src/server.ts
Debug Logging
The server includes comprehensive logging middleware:Client Implementation
Project Structure
Key Integration: x402 Adapter
The critical integration point between Crossmint SDK and x402:client/src/utils/x402Adapter.ts
- Converts Crossmint wallet to x402 Signer interface
- Preserves ERC-6492 pre-deployment signatures
- Handles EIP-1271 deployed wallet signatures
- Maintains compatibility with facilitator
Usage Guide
1. Initialize Wallet
API Key Signer (Simpler)
- Open http://localhost:5174
- Signer Type: Select “API Key”
- API Key: Enter your
sk_staging_...key - Email:
[email protected] - Chain:
base-sepolia - Server URL:
http://localhost:3100 - Click “Initialize Wallet”
Email OTP Signer (More Secure)
- Signer Type: Select “Email OTP”
- API Key: Enter your
ck_staging_...key - Email: Enter accessible email address
- Click “Initialize Wallet”
- Click “Send OTP”
- Check email for 6-digit code
- Enter code and click “Verify OTP”
2. Fund Wallet
Copy the wallet address and fund with testnet tokens:3. Deploy Wallet (Optional but Recommended)
Pre-deployed wallets work for signature verification but may fail at settlement.- Click “Deploy Wallet”
- Wait 30-60 seconds for confirmation
- Status changes to “deployed”
4. Make Payment Request
- Click “Make Ping”
- Server returns 402 Payment Required
5. Approve and Execute Payment
- Review payment details
- Click “Approve Payment”
- Wallet signs authorization (automatic)
- Client retries with X-PAYMENT header
Payment Flow
Signature Formats
Pre-deployed Wallet (ERC-6492)
- Signature includes deployment parameters
- Can be verified off-chain without deployed contract
- Facilitator may fail settlement (requires deployment)
- Demonstrates successful signature verification
Deployed Wallet (EIP-1271)
- Smart contract implements EIP-1271 interface
- On-chain signature validation
- Full settlement support
- Production-ready pattern
API Reference
GET /health
Health check endpoint - no payment required. Request:GET /ping
Protected endpoint requiring $0.001 USDC payment. Request (without payment):Dependencies
Client
Server
Next Steps
Solana Demo
Implement paywalls on Solana blockchain
Weather Demo
Protect dynamic endpoints with query parameters
Crossmint Docs
Deep dive into Crossmint Wallets SDK
x402 Protocol
Read the full x402 specification
Troubleshooting
Wallet Initialization Fails
Error: “Invalid API key” Solution: Usesk_staging_... for API Key signer, ck_staging_... for Email OTP signer.
Payment Settlement Fails
Message: “Payment verification completed, settlement had issues” Status: Expected with pre-deployed wallets. Signature verification works, on-chain settlement requires deployment. Solution: Deploy wallet first for full end-to-end payment flow.Port Already in Use
Error:EADDRINUSE
Solution: