Skip to Content
px402Devnet
How it works

One paid call

Every step from the first request to the paid response.

One paid call
  1. 01
    Agent → px402 gatewayThe agent sends a plain request.
  2. 02
    px402 gateway → AgentThe gateway stores a single-use nonce and answers with the price, asset, receiver shielded address and expiry.
  3. 03
    AgentThe SDK checks the price ceiling, allowed origin and caps, then reserves the nonce in its journal.
  4. 04
    Agent → Solana + HeliusOne Privacy Rings transfer to the receiver. The agent key is the only signer and pays the fee.
  5. 05
    Agent → px402 gatewayThe same request with PAYMENT-SIGNATURE: nonce, transaction signature and a sender proof signed by the agent key.
  6. 06
    px402 gateway → Solana + HeliusThe gateway reads the transaction and decrypts the receiver's output with that provider's viewing key.
  7. 07
    px402 gatewayThe payment is bound to the nonce in Postgres before anything is forwarded.
  8. 08
    px402 gateway → Provider APIThe gateway calls the provider API with the proxy secret, payment id, route id and attempt number.
  9. 09
    Provider API → px402 gatewayThe provider answers.
  10. 10
    px402 gateway → AgentThe agent gets the body and a receipt. The earning is counted once. The receipt leaves out the payer.

The built-in demo route runs inside px402, so there is no forward: claiming the nonce, running the handler and counting the earning happen in one database transaction.

What the agent checks before paying

All of these refuse before anything moves on chain:

CheckError
Price above PX402_MAX_PRICE_BASESDK_PRICE_ABOVE_MAX
Origin not allowed, or the 402 arrived through a redirect to another originSDK_ORIGIN_NOT_ALLOWED
A spending cap would be passedSDK_CAP_EXCEEDED
Another network, asset or binding mode than the wallet supportsSDK_UNSUPPORTED_REQUIREMENT

What the gateway checks

  1. The nonce is known, unexpired and not already used.
  2. The transaction exists and is not older than the nonce.
  3. The claim was signed by the transaction’s single public signer.
  4. A decrypted output pays this receiver at least the price, in the right asset.

Because the claim must be signed by the payer, copying someone’s transaction signature does not let you claim it.

Why you never pay twice

  • The agent writes the nonce to its journal before paying, and the transaction signature after signing and before sending. A crash resumes the claim and does not send a second transfer.
  • If the transfer is not visible yet, the gateway answers 402 TRANSFER_NOT_FOUND and the SDK resends the same claim with backoff, until 2 minutes after the nonce expires.
  • Unique constraints in Postgres mean one nonce is used once and one transfer pays for one nonce.

If a payment is refused after money moved (for example TRANSFER_AMOUNT_TOO_LOW), the journal records it as rejected. Refunds are manual today.

How long it takes

Seconds, not milliseconds. A paid call took about 4 s at p50 in one measurement and about 6 s at p50 through the deployed stack in another; 20 concurrent calls from one wallet measured a p95 of 34 s. These are small devnet samples. Use px402 for fewer, higher-value calls.