End-to-End Payment Demo

Complete demonstration of P402 payment flow with real USDC on Base network

Demo Setup

Network Requirements

  • • Base mainnet (Chain ID: 8453)
  • • USDC balance: minimum $1.00
  • • MetaMask or compatible wallet
  • • Small ETH for gas (if needed)

Demo Parameters

  • • Payment amount: $1 USDC
  • • Treasury: 0xFa772434...
  • • Scheme: EIP-3009 exact
  • • Gasless execution

Payment Flow Steps

1

Connect Wallet

Connect your wallet with USDC on Base network

2

Check USDC Balance

Verify you have sufficient USDC for the demo payment

3

Sign Payment Authorization

Create EIP-3009 transferWithAuthorization signature

4

Verify Payment

P402 facilitator verifies the payment authorization

5

Execute Settlement

Gasless settlement executed by facilitator

6

Generate Receipt

Create reusable payment receipt for future sessions

Integration Guide

Frontend Integration

// 1. Install P402 SDK
npm install @p402/sdk viem

// 2. Initialize client
import { P402Client } from '@p402/sdk';

const p402 = new P402Client({
  routerUrl: 'https://p402.io',
  apiKey: 'your-api-key'
});

// 3. Settle via x402 wire format
const result = await fetch('https://p402.io/api/v1/facilitator/settle', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    paymentPayload: {
      x402Version: 2, scheme: 'exact', network: 'eip155:8453',
      payload: { signature, authorization }
    },
    paymentRequirements: {
      scheme: 'exact', network: 'eip155:8453',
      maxAmountRequired: '1000000',
      payTo: '0xb23f...', asset: '0x8335...',
      resource: '/api', description: 'Payment'
    }
  })
});
const data = await result.json();
console.log(data.transaction); // "0x..."

Backend Integration

// Verify payment server-side (x402 wire format)
const verification = await fetch('https://p402.io/api/v1/facilitator/verify', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    paymentPayload: {
      x402Version: 2, scheme: 'exact', network: 'eip155:8453',
      payload: { signature, authorization: signedAuthorization }
    },
    paymentRequirements: {
      scheme: 'exact', network: 'eip155:8453',
      maxAmountRequired: '1000000',
      payTo: '0xb23f...', asset: '0x8335...',
      resource: '/api', description: 'Payment'
    }
  })
});

const result = await verification.json();
if (result.isValid) {
  console.log('Payer:', result.payer); // "0x..."
  await provideAIService(sessionId);
}

Key Benefits Demonstrated

  • Gasless payments: Users don't pay gas fees for USDC transfers
  • Instant verification: Sub-100ms payment verification
  • Global facilitator: Edge deployment for low latency worldwide
  • Receipt reuse: One payment enables multiple AI sessions
  • Production ready: Real USDC on Base mainnet