How It Works
Three parties each contribute an attribution code:| Field | Set by | Description |
|---|---|---|
a | Resource server | App code — identifies the application exposing the paid endpoint |
w | Facilitator | Wallet code — identifies the facilitator settling the payment on-chain |
s | Client | Service code — client-provided attribution |
Builder Code Format
All codes must match^[a-z0-9_]{1,32}$:
- 1–32 characters
- Lowercase letters, digits, and underscores only
Quickstart for Sellers (Servers)
Declare your app builder code per-route in the payment middleware configuration:declareBuilderCodeExtension validates the code format and returns the extension declaration (including the JSON Schema) for inclusion in the PaymentRequired response.
Quickstart for Buyers (Clients)
Register theBuilderCodeClientExtension on your x402 client. It automatically echoes the server’s app code (a) and attaches your service code (s) to every payment payload:
Quickstart for Facilitators
Register theBuilderCodeFacilitatorExtension on your facilitator. At settlement time it reads a and s from the payment payload, adds its own w code, and appends the ERC-8021 CBOR suffix to the transaction calldata:
Protocol Flow
Verifying Attribution On-Chain
After settlement, you can parse the ERC-8021 suffix from the transaction calldata to verify attribution:ERC-8021 Schema 2 Calldata Format
The suffix appended to settlement calldata (reading from the end backwards):| Component | Size | Description |
|---|---|---|
ercMarker | 16 bytes | Constant: 80218021802180218021802180218021 |
schemaId | 1 byte | 0x02 for Schema 2 |
cborLength | 2 bytes | Length of CBOR data (big-endian) |
cborData | variable | CBOR-encoded map with a, w, and/or s fields |
[cborData][cborLength (2B)][schemaId (1B)][ercMarker (16B)]
API Reference
Server
declareBuilderCodeExtension(appCode)
Validates appCode and returns the extension declaration for PaymentRequired.extensions.
appCode does not match ^[a-z0-9_]{1,32}$.
Client
BuilderCodeClientExtension
a code and attaches the client’s s code to every payment payload.
Facilitator
BuilderCodeFacilitatorExtension
a and s from the payment payload at settlement time, adds w, and encodes the ERC-8021 CBOR suffix.