Minting Builder Codes
Builder codes are minted through any ERC-8021 implementation. Currently, the primary implementation in production is available at base.dev, where you can mint codes for your app, wallet, or service.How It Works
Three parties each contribute an attribution code:
These codes are CBOR-encoded as an ERC-8021 Schema 2 suffix and appended to the settlement transaction calldata. Off-chain tools can parse the calldata to verify 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:- TypeScript
- Go
- Python
declareBuilderCodeExtension / DeclareBuilderCodeExtension validates the code format and returns the extension declaration (including the JSON Schema) for inclusion in the PaymentRequired response. It also accepts optional service code(s), for cases where the application itself wants to attribute a dependency (e.g. a server-side SDK):
Quickstart for Buyers (Clients)
Register theBuilderCodeClientExtension on your x402 client. It attaches your service code (s) to every payment payload when registered. When the server declared builder-code, the core client merge also preserves the server’s app code (a):
- TypeScript
- Go
- Python
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, optionally, its own s entry (up to MAX_FACILITATOR_SERVICE_CODES), and appends the ERC-8021 CBOR suffix to the transaction calldata:
- TypeScript
- Go
- Python
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):
Wire order:
[cborData][cborLength (2B)][schemaId (1B)][ercMarker (16B)]
API Reference
Server
declareBuilderCodeExtension(appCode, serviceCodes?)
Validates appCode and returns the extension declaration for PaymentRequired.extensions.
appCode or any serviceCodes entry does not match ^[a-z0-9_]{1,32}$, or if more than MAX_SERVER_SERVICE_CODES service codes are given.
Client
BuilderCodeClientExtension
s code(s) to every payment payload when registered. When the server declared builder-code, the core client merge also preserves the server’s a code, concatenating any server-declared s with the client’s (client entries first). Multiple codes are useful for layered clients (e.g. an MCP server acting as middleware) that need to attribute multiple participants. Throws if more than MAX_CLIENT_SERVICE_CODES codes are given.
s is split into dedicated, non-overlapping reservations: up to MAX_CLIENT_SERVICE_CODES (5) for the client, MAX_SERVER_SERVICE_CODES (5) for the server, and MAX_FACILITATOR_SERVICE_CODES (1) for the facilitator’s own code — a total of MAX_SERVICE_CODES (11). declareBuilderCodeExtension, BuilderCodeClientExtension, and the facilitator’s serviceCode config each reject more entries than their own reservation, so no compliant combination can crowd out another party’s codes. The resource server also rejects a client echo whose combined s exceeds the client+server budget (10) before settlement, and facilitators additionally truncate to that same budget as a defensive backstop against a malformed payload sent directly to a facilitator.Facilitator
BuilderCodeFacilitatorExtension
a and s from the payment payload at settlement time, adds w, appends its own serviceCode to s (deduped), and encodes the ERC-8021 CBOR suffix.
Utilities
encodeBuilderCodeSuffix(data)
Encodes builder code fields as an ERC-8021 Schema 2 hex suffix.
parseBuilderCodeSuffixFromCalldata(calldata)
Parses ERC-8021 Schema 2 attribution from settlement transaction calldata.
Constants
Examples
Full working examples are available in the x402 repository:- TypeScript Server Example
- TypeScript Client Example
- TypeScript Facilitator Example
- Go Server Example
- Go Client Example
- Go Facilitator Example
- Python Server Example
- Python Client Example
- Python Facilitator Example