Support for x402 protocol v2
The thirdweb SDK now supports x402 protocol version 2, introducing header-based payment flows for improved efficiency and flexibility in blockchain payment integrations.
Notable Changes
- New Payment Headers: v2 uses
PAYMENT-SIGNATUREfor requests andPAYMENT-RESPONSEfor responses, replacing the v1 headers (X-PAYMENTandX-PAYMENT-RESPONSE) - Streamlined Responses: Payment requirements are now encoded in the
PAYMENT-REQUIREDheader rather than the response body, reducing payload size - Backward Compatibility: The SDK maintains full backward compatibility with v1, automatically detecting and handling both protocol versions
Public API Updates
Server-Side Changes
Payment data retrieval now prioritizes v2 headers with fallback to v1:
// Updated header reading pattern
const paymentData =
request.headers.get("PAYMENT-SIGNATURE") ||
request.headers.get("X-PAYMENT");
This change applies to:
settlePayment()- Server-side payment settlementverifyPayment()- Payment verification- Middleware implementations
Configuration Options
New optional x402Version parameter allows explicit version control:
settlePayment({
// ... other options
x402Version: 2 // explicitly use v2
})
Migration Guide
No breaking changes - existing v1 integrations continue to work unchanged. To adopt v2:
- Update header reading to check both headers (as shown above)
- Optionally specify
x402Version: 2in configuration - The SDK handles version negotiation automatically
Documentation
For complete implementation details and examples, see the documentation.