Skip to main content

What is x402?

x402 is a gasless payment protocol that enables AI agents and humans to make blockchain transactions without holding native gas tokens (SOL).

Gasless Transactions

Facilitator pays Solana fees, voter only needs USDC

AI-Native

Designed for AI agents

Atomic Verification

Payment confirmed before resource access granted

Facilitators

x402 requires a facilitator - a third-party service that pays gas fees and broadcasts transactions.
ProviderDevnetMainnetURL
PayAI (Primary)https://facilitator.payai.network
Coinbase (Backup)https://x402.org/facilitator

Vote Payment Flow

Step-by-Step Breakdown

1

1. Initial Vote Request

User requests to vote without payment proof
2

2. API Returns 402 Payment Required

Server calculates dynamic entry fee and returns payment requirementsResponse: 402 Payment RequiredHeaders:
3

3. Build Transaction

Client builds USDC SPL token transfer
4

4. Sign Transaction

User signs transaction (wallet approval)
Voter signs the transaction but does NOT pay gas fees - facilitator pays SOL costs
5

5. Submit Signed Transaction

Client submits signed transaction with X-Payment header
6

6. Payment Verification & Settlement

API verifies and settles payment via facilitator
7

7. Record Vote

After successful settlement, API records vote in database
8

8. Return Confirmation

API returns vote confirmation to client

Payment Requirements Structure

The X-Payment-Required header contains the following information:
  • payTo: The recipient address (poll wallet public key)
  • amount: The entry fee in base units (e.g., “769000” for 0.769 USDC)
  • currency: The SPL token mint address (USDC)
  • resource: The API endpoint URL being accessed
  • extra.feePayer: The x402 facilitator’s fee payer address (pays SOL gas fees)
This structure tells the voter exactly how to construct the payment transaction, including who pays the gas fees (the facilitator, not the voter).

Security Considerations

API verifies transaction structure before settlement:
  • Correct recipient (poll wallet)
  • Correct amount (dynamic entry fee)
  • Correct currency (USDC)
  • Valid signature from voter
After settlement, API waits for blockchain confirmation before recording vote.Benefit: Prevents double-voting and ensures payment actually executed
System trusts facilitator to:
  • Broadcast transactions honestly
  • Pay gas fees
  • Not censor transactions
Mitigation: Multiple facilitators available (PayAI, Coinbase)

Error Handling

Error CodeReasonSolution
402Payment required / invalidBuild and submit proper x402 payment
400Poll expired / already votedCheck poll status, verify voter hasn’t voted
500Facilitator down / settlement failedRetry or use backup facilitator

Next Steps