Feat: 8021 Schema v2 support for x402#2329
Open
0xClouds wants to merge 6 commits into
Open
Conversation
…ments Adds a new builder-code extension that enables ERC-8021 Schema 2 attribution tracking for x402 payments. Three parties can attach their builder code to settlement transactions: - Agent (client): sets the "a" field via BuilderCodeClientExtension - Service (server): declares in 402 response via declareBuilderCodeExtension() - Facilitator: adds to "s" array at settlement via BuilderCodeFacilitatorExtension At settlement, the facilitator encodes all builder codes as a Schema 2 CBOR suffix and appends it to the transferWithAuthorization calldata. The EVM ignores trailing calldata bytes, so the transfer executes normally while indexers (Coindexer, Beacon, Dune) can parse the suffix. Changes: - New extension package: @x402/extensions/builder-code - EVM mechanism: executeTransferWithAuthorization accepts optional calldataSuffix - settleEIP3009 reads builder code extension from FacilitatorContext - scheme.ts passes context through to EIP-3009 settlement
…t extension - Service declares its builder code as "a" (app) — it's the application exposing the x402 endpoint - Facilitator adds its code as "w" (wallet) — it's the entity that signs and broadcasts the settlement transaction - Service can optionally include related on-chain services in "s" array (e.g., Morpho, Aerodrome) - Remove BuilderCodeClientExtension — agent doesn't attach builder codes, the service's extension data passes through untouched - CBOR encoder now handles "a", "w", and "s" fields
|
@0xClouds is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
4 tasks
0xClouds
commented
May 18, 2026
| @@ -0,0 +1,85 @@ | |||
| package main | |||
Contributor
Author
There was a problem hiding this comment.
These examples expect that you run:
- Client
- Facilitator
- Server
in order to test the E2E flow. They do work in isolation but will mock data
Collaborator
|
Hi @0xClouds @pk-coinbase, I opened a PR on top of your branch: pk-coinbase#2 This includes the following TS only changes:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new
builder-codeextension that enables ERC-8021 Schema 2 attribution tracking for x402 payments. Two parties attach their builder code to settlement transactions:"a"(app) field in the 402 response viadeclareBuilderCodeExtension()"w"(wallet) field at settlement viaBuilderCodeFacilitatorExtensionThe service can optionally include related on-chain services (e.g., Morpho, Aerodrome) in the
"s"array to attribute protocols it depends on.At settlement, the facilitator encodes all builder codes as a Schema 2 CBOR suffix and appends it to the
transferWithAuthorizationcalldata. The EVM ignores trailing calldata bytes, so the transfer executes normally while indexers (Coindexer, Beacon, Dune) can parse the suffix.Schema 2 Suffix
Encoded as:
[CBOR data][length 2B][schema_id 0x02][8021 marker 16B]Flow
Why
x402 payments currently have no attribution mechanism. Builder codes (ERC-8021) are the standard for on-chain attribution on Base, but they work by appending a suffix to transaction calldata — which requires the transaction submitter to cooperate. In x402, the client never submits a transaction; the facilitator does. This extension bridges that gap by flowing builder codes through the x402 payment protocol and having the facilitator append them at settlement time.
Out of Scope
Tests
Verified On-Chain
Tested on Base Sepolia with a full service → facilitator flow:
Decoded CBOR from settlement calldata:
Checklist
Changes
New:
@x402/extensions/builder-codetypes.ts— extension key, interfaces, builder code validation; fields:a(app),w(wallet),s(services)cbor.ts— hand-rolled Schema 2 CBOR encoder (no dependencies)resourceServer.ts—declareBuilderCodeExtension(appCode, serviceCodes?)for services to declare their code as"a"with optional"s"arrayfacilitator.ts—BuilderCodeFacilitatorExtensionwithbuildCalldataSuffix()that adds its code as"w"Modified:
@x402/evm(exact facilitator)eip3009-utils.ts—executeTransferWithAuthorization()accepts optionalcalldataSuffix; when present, usesencodeFunctionData()+sendTransaction()instead ofwriteContract()eip3009.ts—settleEIP3009()acceptsFacilitatorContext, reads builder code extension, passes suffixscheme.ts— passescontexttosettleEIP3009()