Developer Guide

Integrate gasless USDC payments with simple HTTP requests.

TypeScript SDK

Install the official TypeScript SDK — or use raw HTTP if you prefer.

npm install @p402/sdk
# or: npm install @p402/cli

Quick Start

P402 works with your existing code. No SDK required - just API calls.

# No installation needed - use standard HTTP requests
# Compatible with fetch(), axios, curl, or any HTTP client

Payment Verification

Verify EIP-3009 gasless payment authorizations before settling.

// 1. Verify Payment Authorization (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: '0x...',   // 65-byte EIP-3009 signature
        authorization: {
          from: '0x...',      // User's wallet
          to: '0xb23f...',    // P402 treasury
          value: '1000000',   // 1 USDC (6 decimals)
          validAfter: '0',
          validBefore: '1735689600',
          nonce: '0x...'
        }
      }
    },
    paymentRequirements: {
      scheme: 'exact',
      network: 'eip155:8453',
      maxAmountRequired: '1000000',
      resource: 'https://example.com/api',
      description: 'AI inference',
      payTo: '0xb23f...',
      asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
    }
  })
});

const result = await verification.json();
console.log('Valid:', result.isValid);   // true
console.log('Payer:', result.payer);     // "0x..."

Gasless Settlement Execution

Execute gasless USDC transfers using P402's facilitator network.

// 2. Execute Gasless Settlement (x402 Wire Format)
const settlement = 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: '0x...',
        authorization: signedAuthorization // From step 1
      }
    },
    paymentRequirements: {
      scheme: 'exact',
      network: 'eip155:8453',
      maxAmountRequired: '1000000',
      resource: 'https://example.com/api',
      description: 'AI inference',
      payTo: '0xb23f...',
      asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
    }
  })
});

const result = await settlement.json();
if (result.success) {
  console.log('Transaction:', result.transaction);  // "0x..."
  console.log('Network:', result.network);           // "eip155:8453"
  console.log('Payer:', result.payer);               // "0x..."
} else {
  console.error('Failed:', result.errorReason);
}

Receipt Management

Create and reuse payment receipts for multiple sessions.

// 3. Create Reusable Receipt
const receiptResponse = await fetch('https://p402.io/api/v1/receipts', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    txHash: '0x...',           // From settlement
    sessionId: 'session_123',
    amount: 1.0,
    metadata: {
      payer: '0x...',
      network: 'eip155:8453',
      token: 'USDC'
    }
  })
});

const receipt = await receiptResponse.json();
console.log('Receipt ID:', receipt.receiptId);
console.log('Valid Until:', receipt.validUntil);

// 4. Verify Receipt for Future Use
const receiptVerify = await fetch(`https://p402.io/api/v1/receipts?receipt_id=${receipt.receiptId}`);
const verification = await receiptVerify.json();
console.log('Receipt Valid:', verification.success);