Skip to content

Align 402 response field names with x402 V2 spec #7

Description

@andreabadesso

Current behavior

Our 402 response uses some field names that differ from the x402 V2 spec:

{
  "accepts": [{
    "scheme": "hathor-escrow",
    "network": "hathor:testnet",
    "asset": "00",
    "amount": "100",
    "description": "Pay 1.00 HTR",
    "payTo": "WZe3ty22...",
    "maxTimeoutSeconds": 300,
    "extra": {
      "facilitatorUrl": "https://facilitator.x402.hathor.dev",
      "facilitatorAddress": "Wb6eLTZS...",
      "blueprintId": "0000121e...",
      "deadlineSeconds": 300
    }
  }]
}

x402 V2 spec field names

The V2 spec uses these field names in the accepts array entries:

  • scheme ✅ (matches)
  • network ✅ (matches)
  • asset ✅ (matches)
  • price — we use amount. The spec calls it price.
  • payTo ✅ (matches)
  • description ✅ (matches)
  • resource ✅ (matches)
  • mimeType ✅ (matches)

The extra field is Hathor-specific (escrow blueprint ID, facilitator address, deadline). The spec doesn't define this — each scheme can add its own fields.

Changes needed

Resource server (resource-server.js)

  • Rename amount to price in the 402 response
  • Keep amount in the facilitator verify/settle payloads (internal, not spec-facing)

Client (client.js) and dApp (dapp/components/X402Fetch.tsx)

  • Read price instead of amount from 402 responses

Facilitator (facilitator.js)

  • Accept both maxAmountRequired and price in verify requests for compatibility

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions