Overview
CreditNexus integrates with the x402 payment protocol for blockchain-based payment processing using USDC stablecoin on the Base network. The system provides CDM-compliant payment interfaces for loan disbursements, trade settlements, interest payments, and penalties. Code Reference:app/services/x402_payment_service.py, app/api/routes.py (x402 endpoints), client/src/hooks/useX402Payment.ts
x402 Protocol
The x402 protocol is a standard for HTTP 402 “Payment Required” responses that enables seamless payment processing in web applications. CreditNexus implements x402 for:- Loan Disbursements: Automated loan funding
- Trade Settlements: Payment for trade executions
- Interest Payments: Periodic interest distributions
- Penalties: Late payment fees and penalties
- Notarization Fees: Payment for blockchain notarization
Key Features
Payment Request Generation
Generate HTTP 402 responses with payment instructions:app/services/x402_payment_service.py (request_payment)
Payment Verification
Verify payment completion on the blockchain:app/services/x402_payment_service.py (verify_payment)
CDM Integration
All payments are CDM-compliant:- Money Objects: Use CDM Money type
- Party References: Link to CDM Party objects
- Event Tracking: Generate CDM payment events
app/models/cdm.py (Money, Currency, Party)
Base Network Integration
Network Configuration
CreditNexus uses Base network (Coinbase Layer 2) for payments:- Mainnet:
https://mainnet.base.org(production) - Sepolia Testnet:
https://sepolia.base.org(development)
app/core/config.py (X402_NETWORK_RPC_URL)
USDC Token
Payments use USDC stablecoin on Base network:- Mainnet Address:
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 - Sepolia Address: Check Base Sepolia documentation
app/core/config.py (USDC_TOKEN_ADDRESS)
Workflow
1. Payment Request
- Generate Request: System generates x402 payment request
- Return 402 Response: API returns HTTP 402 with payment instructions
- Client Processing: Frontend receives payment request
- Wallet Connection: User connects MetaMask wallet
- Payment Approval: User approves payment in wallet
2. Payment Execution
- Submit Payment: Client submits payment via x402 facilitator
- Blockchain Transaction: Payment processed on Base network
- Transaction Hash: Receive blockchain transaction hash
- Verification: System verifies payment on blockchain
- Settlement: Complete payment settlement
3. Payment Confirmation
- CDM Event: Generate CDM payment event
- Database Update: Update payment records
- Notification: Notify relevant parties
- Audit Log: Record in audit trail
API Integration
Trade Settlement with x402
Settle a trade with x402 payment. Returns HTTP 402 if payment required. Request:app/api/routes.py (settle_trade endpoint)
Frontend Integration
useX402Payment Hook
Location:client/src/hooks/useX402Payment.ts
React hook for x402 payment processing:
client/src/hooks/useX402Payment.ts
Configuration
Environment Variables
Enable x402 payment processing. Default:
truex402 facilitator service URL. Default:
https://facilitator.x402.orgBlockchain network. Default:
"base"Token symbol. Default:
"USDC"Base network RPC URL
Payment Types
Loan Disbursement
Initial loan funding to borrower.Trade Settlement
Payment for executed trades.Interest Payment
Periodic interest distributions.Penalty Payment
Late payment fees and penalties.Notarization Fee
Payment for blockchain notarization services. Code Reference:app/services/x402_payment_service.py (payment_type parameter)
Security Considerations
- Wallet Security: Users must secure their MetaMask wallets
- Transaction Verification: All payments verified on blockchain
- Amount Validation: Validate payment amounts before processing
- Network Confirmation: Wait for blockchain confirmations
- Audit Trail: Complete CDM event trail for all payments
Troubleshooting
Payment Not Processing
- Verify MetaMask is connected
- Check network is set to Base (Mainnet or Sepolia)
- Verify USDC balance in wallet
- Check transaction gas fees
Payment Verification Fails
- Verify transaction hash is correct
- Check blockchain explorer for transaction status
- Ensure sufficient confirmations received
- Review payment payload format
Additional Resources
Last Updated: 2026-01-14
Code Reference:
app/services/x402_payment_service.py, app/api/routes.py, client/src/hooks/useX402Payment.ts