DNAbyD3Docs

Pay with x402

How an agent pays for a priced page with a signed x402 authorization.

A site on DNA can price a page. An agent that requests it without paying gets a 402 with terms. The agent signs a payment authorization, retries with it, and gets the page and a receipt.

A 402 can list two methods: d3-pay, where a person approves the payment (Pay with DNA), and x402 (this page). Use the first one you support.

The exchange

  1. Request the page. You get a 402 with the terms in payment-required.
  2. Pick one entry from accepts, sign it, and retry with payment-signature.
  3. On success you get the page and payment-response.
HeaderOnValue
payment-requiredthe 402Base64 JSON: accepts[] and resource. The terms are here, not in the body.
payment-signatureyour retryBase64 JSON: the signed authorization. Send x-payment instead if you speak x402 v1.
payment-responsethe paid responseBase64 JSON receipt naming the transaction. x-payment-response for v1.

Terms

  • The scheme is exact. Networks are CAIP-2, such as eip155:8453.
  • accepts has one entry per token the site accepts, each the page's dollar price in that token's units. Pay with any of them.
  • Amounts are atomic units. maxAmountRequired has no decimals; read them from the token.
  • Terms are valid for 300 seconds.
  • The payment header is capped at 4096 bytes.
  • Use a new nonce per attempt. A reused one returns nonce_already_used.
  • A refusal includes the terms again, so you can fix the payload and retry without a new request.
  • ambiguous_route and invalid_path include no terms, because no single price applies.
  • A request carrying both an x402 payment and a DNA credential is handled as x402.
  • In a browser, payment-required on the 402 and payment-response on the paid response are listed in access-control-expose-headers, so you can read them.

Errors

Each error is a JSON body with an error field.

StatuserrorMeaning and action
402invalid_payloadThe header didn't decode, or matched none of the offered terms.
402invalid_payment_requirementsTwo offered terms match your payload. Narrow the amount or the network.
402nonce_already_usedSign again with a new nonce.
402insufficient_fundsThe payer's balance is below the price.
402other x402 reasonsThe provider's standard reason, passed through, such as invalid_network or invalid_exact_evm_payload_signature.
402settlement_refusedThe provider refused for a reason outside the standard set.
402ambiguous_routeThe site prices this request twice. Tell the site; no retry fixes it.
402invalid_pathThe requested path couldn't be determined. Send /, \, and . unencoded.
502payment_unavailableA DNA failure. Sign again with a new nonce; the old authorization stays claimed.

A 502 is a refusal: a request that presents a payment never falls through to the page for free.

On this page