-
Notifications
You must be signed in to change notification settings - Fork 304
Add Builder Code Docs (ERC-8021) #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| --- | ||
| title: "Builder Codes" | ||
| description: "Integrate Builder Codes to attribute onchain activity to your app or wallet." | ||
| --- | ||
|
|
||
| Builder Codes allow you to attribute onchain activity to your app or wallet, unlocking analytics, rewards, and future incentives. This guide covers the implementation steps for both application developers and wallet providers. | ||
|
|
||
| ## For App Developers | ||
|
|
||
| Integrating Builder Codes requires appending a suffix—provided by Base—to your transaction data. | ||
|
|
||
| <Steps> | ||
| <Step title="Get your Builder Code and Suffix"> | ||
| When you register on **base.dev**, you will receive: | ||
|
|
||
| * **Builder Code**: A random string (e.g., `k3p9da`). | ||
| * **ERC-8021 Suffix**: A hex-encoded string (e.g., `0x...`). | ||
|
|
||
| You will use the **suffix** to attribute transactions to your app. | ||
| </Step> | ||
|
|
||
| <Step title="Append the Suffix to Transactions"> | ||
| The recommended way to attach your suffix is using `wallet_sendCalls` (ERC-5792). This passes the suffix through a capability, allowing the wallet to handle the attachment automatically for both EOA and Smart Account (ERC-4337) users. | ||
|
|
||
| <Tabs> | ||
| <Tab title="Wagmi (Recommended)"> | ||
| Use the `useSendCalls` hook from Wagmi's experimental features to pass the `dataSuffix` capability. | ||
|
|
||
| ```typescript lines highlight={14-16} | ||
| import { useSendCalls } from 'wagmi/experimental' | ||
|
|
||
| // Your suffix provided by base.dev | ||
| const dataSuffix = "0x1234abcd..." | ||
|
|
||
| function SendTx() { | ||
| const { sendCalls } = useSendCalls() | ||
|
|
||
| async function submit() { | ||
| await sendCalls({ | ||
| calls: [ | ||
| { | ||
| to: "0xYourContract", | ||
| data: "0xYourCalldata" | ||
| } | ||
| ], | ||
| capabilities: { | ||
| dataSuffix: dataSuffix | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| return <button onClick={submit}>Send</button> | ||
| } | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Viem"> | ||
| If you are using Viem directly, pass the `dataSuffix` in the `capabilities` object. | ||
|
|
||
| ```typescript lines highlight={11-13} | ||
| import { walletClient } from './client' | ||
|
|
||
| const dataSuffix = "0x1234abcd..." | ||
|
|
||
| await walletClient.sendCalls({ | ||
| calls: [ | ||
| { | ||
| to: "0xYourContract", | ||
| data: "0xYourCalldata" | ||
| } | ||
| ], | ||
| capabilities: { | ||
| dataSuffix: dataSuffix | ||
| } | ||
| }) | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Legacy (writeContract)"> | ||
| If you are restricted to `writeContract` (EOA only), you must manually append the suffix to the calldata. This is **not recommended** as it does not support Smart Accounts automatically. | ||
|
|
||
| ```typescript lines highlight={15} | ||
| import { encodeFunctionData } from 'viem' | ||
|
|
||
| // 1. Encode your function call | ||
| const encoded = encodeFunctionData({ | ||
| abi, | ||
| functionName: "yourFn", | ||
| args: [a, b, c], | ||
| }) | ||
|
|
||
| // 2. Manually append the suffix (stripping the '0x' prefix from the suffix) | ||
| const dataWithSuffix = encoded + dataSuffix.slice(2) | ||
|
|
||
| // 3. Send the transaction | ||
| await sendTransaction({ | ||
| to: "0xYourContract", | ||
| data: dataWithSuffix, | ||
| }) | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| Once you have added the suffix, your app is fully ERC-8021 compliant. | ||
|
|
||
| --- | ||
|
|
||
| ## For Wallet Developers | ||
|
|
||
| Wallet providers need to support the `dataSuffix` capability to enable attribution. This involves accepting the capability and appending the suffix to the calldata before signing. | ||
|
|
||
| <Steps> | ||
| <Step title="Support the dataSuffix Capability"> | ||
| Your wallet should accept a `dataSuffix` string in the `capabilities` object of `wallet_sendCalls`. | ||
|
|
||
| ```typescript lines | ||
| interface DataSuffixCapability { | ||
| dataSuffix: string; // hex-encoded bytes provided by the app | ||
| } | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Append Suffix to Calldata"> | ||
| When constructing the transaction or User Operation, extract the `dataSuffix` and append it to the calldata. | ||
|
|
||
| <Tabs> | ||
| <Tab title="EOA Transactions"> | ||
| Append to `tx.data`. | ||
|
|
||
| ```typescript lines | ||
| // Minimal example for EOA | ||
| function applySuffixToEOA(tx, capabilities) { | ||
| const suffix = capabilities.find(c => c.dataSuffix)?.dataSuffix | ||
| if (!suffix) return tx | ||
|
|
||
| return { | ||
| ...tx, | ||
| // Append suffix bytes (remove 0x prefix from suffix if tx.data has it) | ||
| data: tx.data + suffix.slice(2) | ||
| } | ||
| } | ||
| ``` | ||
| </Tab> | ||
| <Tab title="ERC-4337 User Operations"> | ||
| Append to `userOp.callData` (not the transaction-level calldata). | ||
|
|
||
| ```typescript lines | ||
| // Minimal example for ERC-4337 | ||
| function applySuffixToUserOp(userOp, capabilities) { | ||
| const suffix = capabilities.find(c => c.dataSuffix)?.dataSuffix | ||
| if (!suffix) return userOp | ||
|
|
||
| return { | ||
| ...userOp, | ||
| // Append suffix bytes to the UserOp callData | ||
| callData: userOp.callData + suffix.slice(2) | ||
| } | ||
| } | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
| </Step> | ||
| <Step title="(Optional) Add Wallet Attribution"> | ||
| Wallets may also include their own attribution code (their own ERC-8021 suffix) by simply prepending the wallet’s own suffix before the app’s. | ||
|
|
||
| * **No interaction required with apps:** The wallet handles this independently. | ||
| * **Multi-code support:** ERC-8021 natively supports multiple attribution codes. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```typescript | ||
| finalSuffix = walletSuffix + appSuffix | ||
| ``` | ||
|
|
||
| This ensures both the app and the wallet receive onchain attribution. | ||
| </Step> | ||
| </Steps> | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.