Skip to content

Commit 2d68eee

Browse files
Add Builder Code Docs (ERC-8021) (#665)
* Add builder code docs * Update docs/base-chain/quickstart/builder-codes.mdx Co-authored-by: Conner Swenberg <[email protected]> * update to use only builder code --------- Co-authored-by: Conner Swenberg <[email protected]>
1 parent 97bcba4 commit 2d68eee

File tree

3 files changed

+191
-2
lines changed

3 files changed

+191
-2
lines changed

docs/base-chain/quickstart/base-solana-bridge.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: "Base-Solana Bridge"
33
description: "Bridge tokens and messages between Base and Solana"
4-
icon: "bridge"
54
---
65

76
import { GithubRepoCard } from "/snippets/GithubRepoCard.mdx"
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
---
2+
title: "Builder Codes"
3+
description: "Integrate Builder Codes to attribute onchain activity to your app or wallet."
4+
---
5+
6+
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.
7+
8+
## For App Developers
9+
10+
Integrating Builder Codes requires appending a suffix—provided by Base—to your transaction data.
11+
12+
<Steps>
13+
<Step title="Get your Builder Code">
14+
When you register on **base.dev**, you will receive a **Builder Code**. This is a random string (e.g., `k3p9da`) that you will use to generate your attribution suffix.
15+
</Step>
16+
17+
<Step title="Append the Suffix to Transactions">
18+
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.
19+
20+
<Tabs>
21+
<Tab title="Wagmi (Recommended)">
22+
Use the `useSendCalls` hook from Wagmi's experimental features to pass the `dataSuffix` capability.
23+
24+
```typescript lines highlight={14-16}
25+
import { useSendCalls } from 'wagmi/experimental'
26+
import { Attribution } from 'ox/erc8021'
27+
28+
// Your builder code provided by base.dev
29+
const builderCode = "abcd1234"
30+
const dataSuffix = Attribution.toDataSuffix({
31+
codes: [builderCode]
32+
})
33+
34+
function SendTx() {
35+
const { sendCalls } = useSendCalls()
36+
37+
async function submit() {
38+
await sendCalls({
39+
calls: [
40+
{
41+
to: "0xYourContract",
42+
data: "0xYourCalldata"
43+
}
44+
],
45+
capabilities: {
46+
dataSuffix: dataSuffix
47+
}
48+
})
49+
}
50+
51+
return <button onClick={submit}>Send</button>
52+
}
53+
```
54+
</Tab>
55+
<Tab title="Viem">
56+
If you are using Viem directly, pass the `dataSuffix` in the `capabilities` object.
57+
58+
```typescript lines highlight={11-13}
59+
import { walletClient } from './client'
60+
import { Attribution } from 'ox/erc8021'
61+
62+
// Your builder code provided by base.dev
63+
const builderCode = "abcd1234"
64+
const dataSuffix = Attribution.toDataSuffix({
65+
codes: [builderCode]
66+
})
67+
68+
await walletClient.sendCalls({
69+
calls: [
70+
{
71+
to: "0xYourContract",
72+
data: "0xYourCalldata"
73+
}
74+
],
75+
capabilities: {
76+
dataSuffix: dataSuffix
77+
}
78+
})
79+
```
80+
</Tab>
81+
<Tab title="Legacy (writeContract)">
82+
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.
83+
84+
```typescript lines highlight={15}
85+
import { encodeFunctionData } from 'viem'
86+
import { Attribution } from 'ox/erc8021'
87+
88+
// Your builder code provided by base.dev
89+
const builderCode = "abcd1234"
90+
const dataSuffix = Attribution.toDataSuffix({
91+
codes: [builderCode]
92+
})
93+
94+
// 1. Encode your function call
95+
const encoded = encodeFunctionData({
96+
abi,
97+
functionName: "yourFn",
98+
args: [a, b, c],
99+
})
100+
101+
// 2. Manually append the suffix (stripping the '0x' prefix from the suffix)
102+
const dataWithSuffix = encoded + dataSuffix.slice(2)
103+
104+
// 3. Send the transaction
105+
await sendTransaction({
106+
to: "0xYourContract",
107+
data: dataWithSuffix,
108+
})
109+
```
110+
</Tab>
111+
</Tabs>
112+
</Step>
113+
</Steps>
114+
115+
Once you have added the suffix, your app is fully ERC-8021 compliant.
116+
117+
---
118+
119+
## For Wallet Developers
120+
121+
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.
122+
123+
<Steps>
124+
<Step title="Support the dataSuffix Capability">
125+
Your wallet should accept a `dataSuffix` string in the `capabilities` object of `wallet_sendCalls`.
126+
127+
```typescript lines
128+
interface DataSuffixCapability {
129+
dataSuffix: string; // hex-encoded bytes provided by the app
130+
}
131+
```
132+
</Step>
133+
134+
<Step title="Append Suffix to Calldata">
135+
When constructing the transaction or User Operation, extract the `dataSuffix` and append it to the calldata.
136+
137+
<Tabs>
138+
<Tab title="EOA Transactions">
139+
Append to `tx.data`.
140+
141+
```typescript lines
142+
// Minimal example for EOA
143+
function applySuffixToEOA(tx, capabilities) {
144+
const suffix = capabilities.find(c => c.dataSuffix)?.dataSuffix
145+
if (!suffix) return tx
146+
147+
return {
148+
...tx,
149+
// Append suffix bytes (remove 0x prefix from suffix if tx.data has it)
150+
data: tx.data + suffix.slice(2)
151+
}
152+
}
153+
```
154+
</Tab>
155+
<Tab title="ERC-4337 User Operations">
156+
Append to `userOp.callData` (not the transaction-level calldata).
157+
158+
```typescript lines
159+
// Minimal example for ERC-4337
160+
function applySuffixToUserOp(userOp, capabilities) {
161+
const suffix = capabilities.find(c => c.dataSuffix)?.dataSuffix
162+
if (!suffix) return userOp
163+
164+
return {
165+
...userOp,
166+
// Append suffix bytes to the UserOp callData
167+
callData: userOp.callData + suffix.slice(2)
168+
}
169+
}
170+
```
171+
</Tab>
172+
</Tabs>
173+
</Step>
174+
<Step title="(Optional) Add Wallet Attribution">
175+
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.
176+
177+
* **No interaction required with apps:** The wallet handles this independently.
178+
* **Multi-code support:** ERC-8021 natively supports multiple attribution codes.
179+
180+
**Example:**
181+
182+
```typescript
183+
finalSuffix = walletSuffix + appSuffix
184+
```
185+
186+
This ensures both the app and the wallet receive onchain attribution.
187+
</Step>
188+
</Steps>
189+

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
"base-chain/quickstart/deploy-on-base",
9191
"base-chain/quickstart/connecting-to-base",
9292
"base-chain/quickstart/bridge-token",
93-
"base-chain/quickstart/base-solana-bridge"
93+
"base-chain/quickstart/base-solana-bridge",
94+
"base-chain/quickstart/builder-codes"
9495
]
9596
},
9697
{

0 commit comments

Comments
 (0)