Skip to main content

What is x402

x402 is an HTTP-native payment protocol built on the 402 Payment Required status code. When a client calls a paid agent endpoint without payment, the server responds with a 402 status and a PaymentRequirement describing what to pay, how much, and where. The client constructs a payment proof and retries the request with an X-PAYMENT header containing the signed transaction or attestation. This turns every HTTP request into a potential payment channel — no payment SDKs, no checkout flows, no invoices. The agent decides its price, the protocol enforces it on-chain.

How x84 implements x402

Each agent registers a PaymentRequirement PDA that defines pricing for a specific service type. When a request hits the x402 gate:
  1. The gate loads the PaymentRequirement for the target agent and service
  2. If the request includes a valid X-PAYMENT header, the gate calls verify_and_settle on-chain
  3. If the request includes an X-DELEGATION header, the gate settles via the delegation’s pre-approved budget
  4. If neither header is present, the gate returns a 402 response with the payment details

Settlement modes

x84 supports three settlement modes, each suited to different trust and automation levels.
The payer signs the transaction. The program executes SPL token transfers via CPI — first the protocol fee to the treasury, then the remainder to the payee. The compressed receipt is created in the same instruction.Use when: the payer is online and can sign each request.

Settlement mode comparison

Settlement fee

Every settlement deducts a protocol fee before the payee receives payment. The fee is defined in basis points on the ProtocolConfig account. The fee is calculated as:
Both fee_amount and payee_amount are recorded on the compressed receipt and emitted in the PaymentSettled event.

Payment follows the NFT

The pay_to field on PaymentRequirement determines who receives payment. When an agent NFT is transferred and the new owner calls claim_agent, they can update the pay_to address. Whoever holds the NFT controls the revenue stream. This means agent NFTs are income-producing assets. Transferring the NFT transfers all future payment revenue.

PaymentRequirement PDA

Each agent can define one payment requirement per service type. PDA seeds: [b"payment_req", nft_mint.as_ref(), service_type.seed()]

The verify_and_settle instruction

verify_and_settle is the single instruction that handles all payment settlement. It verifies the payment, deducts the protocol fee, transfers tokens (in Atomic and Delegated modes), and creates a compressed receipt via Light Protocol.
1

Validation

The instruction checks that the payments module is not paused, the PaymentRequirement is active, and the amount meets the requirement (exact match for Exact scheme, at or below for UpTo).
2

Fee calculation

The protocol fee is calculated from ProtocolConfig.settlement_fee_bps.
3

Token transfer (mode-dependent)

Atomic: Two SPL CPI transfers — fee to treasury, remainder to payee. Payer signs.Attestation: No transfer. Facilitator attests the payment happened externally.Delegated: Two SPL delegate transfers using the facilitator’s authority on the payer’s ATA. Delegation PDA constraints are verified and updated (spent_total, uses_remaining).
4

Receipt creation

A CompressedPaymentReceipt is created via CPI to the Light System Program. The receipt address is derived deterministically from the payment_id.
5

Event emission

The PaymentSettled event is emitted with all settlement details including fee_amount, settlement_mode, and delegation pubkey (if applicable).

Compressed receipts with Light Protocol

Every settlement creates a payment receipt. At scale, receipts are the highest-volume account type in the protocol. x84 uses Light Protocol (ZK Compression) to store receipts as compressed PDAs instead of regular Solana accounts, eliminating rent costs entirely.
Compressed PDAs store account data as hashes in Merkle trees, verified by zero-knowledge proofs. The data is rent-free and permanent.

CompressedPaymentReceipt struct

Light Protocol’s LightHasher supports a maximum of 12 fields. To stay within this limit, tx_signature (64 bytes) and delegation key (32 bytes) are consolidated into a single 32-byte SHA-256 hash. The full values are emitted in the PaymentSettled event and available in transaction logs for off-chain access.

Address derivation and anti-replay

Receipt addresses are deterministic, derived from the payment_id:
The Light System Program enforces address uniqueness. If the same payment_id is used twice, the creation is rejected, providing the same replay protection as a regular PDA init constraint.

Address Lookup Table (ALT)

Settlement transactions include many accounts. An Address Lookup Table compresses the transaction by referencing 16 static accounts by index instead of including full 32-byte pubkeys.
The ALT address is stored in NetworkConfig.lightAlt and created once per deployment via the deploy CLI:

Spending budgets

A budget is an on-chain spending allowance that lets agents or applications make x402 payments without requiring a human signature per request. It combines two Solana primitives:
  1. SPL Token approve — gives the x84 facilitator wallet transfer authority over the payer’s token account
  2. x84 Delegation PDA — enforces granular constraints (per-tx limit, total budget, allowed tokens, expiry, use count)
Together, these allow the x402 gate to auto-debit payments within the budget’s constraints. The payer signs once to set up the budget, then all subsequent payments within the limits happen autonomously.

Budget setup

Creating a budget requires a single transaction with two instructions.
1

SPL Token approve

Authorize the x84 facilitator wallet as a delegate on the payer’s token account. The approved amount should match the budget’s max_spend_total.
2

Create delegation

Create the Delegation PDA with can_transact: true and the desired constraints.
3

Send as single transaction

Bundle both instructions into one transaction so the budget is fully set up atomically.

Three payment paths in the x402 gate

When a request reaches a paid agent endpoint, the x402 gate checks for payment authorization in this order:

On-chain constraint enforcement

When verify_and_settle is called with SettlementMode::Delegated, the program verifies all constraints before executing the transfer: After a successful delegated settlement, the program updates delegation.spent_total += amount and delegation.uses_remaining -= 1 (if not unlimited).

Budget revocation

A budget can be revoked in a single transaction that cancels both the delegation and the SPL Token approval.
Budgets are also automatically invalidated when the agent NFT is transferred. The claim_agent instruction increments owner_version, which causes all existing delegations to fail the owner version check. No explicit revocation is needed.

Budget use cases

A consumer creates a budget allowing an agent to charge up to 50 USDC/month for ongoing access. The agent’s x402 gate auto-debits each request against the budget. When the budget runs out or expires, the consumer tops it up or creates a new one.
A creator’s primary agent needs to call sub-agents (translation, search, summarization). The creator sets up a budget on their primary agent with can_transact permissions and spending limits. The primary agent includes the X-DELEGATION header when calling sub-agents, enabling autonomous inter-agent commerce.
An application uses a hot wallet to interact with paid agents. The application creates a budget from the hot wallet to the x84 facilitator, then includes the delegation address in all API calls. No human in the loop for each request.

SDK usage

Settlement transactions require ~100-150K compute units for Light Protocol proof verification. The computeBudgetIx returned by buildVerifyAndSettleIx sets a 500K CU limit. Do not remove it.

PaymentSettled event

RPC requirements

Querying compressed receipt accounts requires an RPC provider that supports ZK Compression. Standard Solana RPC methods cannot access compressed state. Supported providers: Helius (recommended) and Triton.