You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -5,104 +5,227 @@ description: "Integrate Builder Codes to attribute onchain activity to your app
5
5
6
6
## What are Builder Codes
7
7
8
-
Base Builder Codes are an ERC-721 NFT collection where unique codes (e.g. “abc123”) are minted to help identify builders onchain.
8
+
Base Builder Codes are an ERC-721 NFT collection where unique codes (e.g. "abc123") are minted to help identify builders onchain.
9
9
10
-
Each code has associated metadata. Onchain metadata primarily includes a “payout address” where each code declares where potential rewards should be sent to. Offchain metadata includes more details about the app including its name and site.
10
+
Each code has associated metadata. Onchain metadata primarily includes a "payout address" where each code declares where potential rewards should be sent to. Offchain metadata includes more details about the app including its name and site.
11
11
12
12
## Automatic Builder-Code Attribution on Base
13
13
14
14
Once your app is registered on [Base.dev](http://base.dev/), the Base App will auto-append your Base Builder Code to transactions its users make in your app (e.g. via your mini app, or the Base App's browser). This powers your onchain analytics in [Base.dev](http://base.dev/) and qualifies you for potential future rewards.
15
15
16
-
17
16
## For App Developers
18
17
19
-
When you register on [base.dev](https://base.dev/), you will receive a **Builder Code**—a random string (e.g., `bc_b7k3p9da`) that you'll use to generate your attribution suffix.
18
+
When you register on [base.dev](https://base.dev/), you will receive a **Builder Code**—a random string (e.g., `bc_b7k3p9da`) that you'll use to generate your attribution suffix.
20
19
21
20
<Tip>
22
21
You can find your code anytime under **Settings** → **Builder Code**.
23
22
</Tip>
24
23
25
-
<Steps>
26
-
<Steptitle="Install the Standard Library for Ethereum">
24
+
The recommended approach is to configure `dataSuffix` at the client level, which automatically appends your Builder Code to all transactions.
25
+
26
+
<Note>
27
+
Requires [viem](https://viem.sh) version 2.45.0 or higher, or [wagmi](https://wagmi.sh) version 2.17.0 or higher.
28
+
</Note>
27
29
28
-
This will allow you to append the encoded version of your builder code.
30
+
### Quick setup with Wagmi
29
31
30
-
```bash Terminal
31
-
npm i ox
32
-
```
33
-
</Step>
32
+
<Steps>
33
+
<Steptitle="Install dependencies">
34
+
Install the required packages. The `dataSuffix` feature requires viem version 2.45.0 or higher.
34
35
35
-
<Steptitle="Copy Your Builder Code">
36
-
Navigate to **base.dev > Settings > Builder Codes** to find your unique builder code.
36
+
```bash
37
+
npm i ox wagmi viem
38
+
```
37
39
</Step>
38
40
39
-
<Steptitle="Create the Encoded Data Suffix">
40
-
Use the `Attribution.toDataSuffix` method from the `ox` library to encode your builder code:
41
+
<Steptitle="Configure your Wagmi client">
42
+
Add the `dataSuffix` option to your Wagmi config. This automatically appends your Builder Code to all transactions.
41
43
42
-
```ts App.tsx
44
+
```ts config.ts
45
+
import { createConfig, http } from"wagmi";
46
+
import { base } from"wagmi/chains";
43
47
import { Attribution } from"ox/erc8021";
44
48
49
+
// Get your Builder Code from base.dev > Settings > Builder Codes
<Steptitle="Send transaction using the dataSuffix capability">
52
-
Use Wagmi's `useSendCalls` hook with the `dataSuffix` capability to append attribution data to your transactions.
64
+
<Steptitle="Use Wagmi hooks as usual">
65
+
With the config in place, all transactions automatically include your Builder Code—no changes to your hooks or components. This works with both `useSendTransaction` and `useSendCalls`.
53
66
54
-
```ts App.tsx
55
-
import { useSendCalls } from"wagmi";
67
+
```tsx App.tsx
68
+
import { useSendTransaction } from"wagmi";
56
69
import { parseEther } from"viem";
57
-
import { Attribution } from"ox/erc8021";
58
70
59
-
const DATA_SUFFIX =Attribution.toDataSuffix({
60
-
codes: ["YOUR-BUILDER-CODE"],
61
-
});
62
-
63
-
function App() {
64
-
const { sendCalls } =useSendCalls();
71
+
function SendButton() {
72
+
const { sendTransaction } =useSendTransaction();
65
73
66
74
return (
67
75
<button
68
76
onClick={() =>
69
-
sendCalls({
70
-
calls: [
71
-
{
72
-
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
73
-
value: parseEther("1"),
74
-
},
75
-
{
76
-
data: "0xdeadbeef",
77
-
to: "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
78
-
},
79
-
],
80
-
capabilities: {
81
-
dataSuffix: {
82
-
value: DATA_SUFFIX,
83
-
optional: true,
84
-
},
85
-
},
77
+
sendTransaction({
78
+
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
79
+
value: parseEther("0.01"),
86
80
})
87
81
}
88
82
>
89
-
Sendcalls
83
+
Send ETH
90
84
</button>
91
85
);
92
86
}
93
87
```
94
88
</Step>
95
89
</Steps>
96
90
91
+
### Quick setup with Viem
92
+
93
+
<Steps>
94
+
<Steptitle="Install dependencies">
95
+
Install the required packages. The `dataSuffix` feature requires viem version 2.45.0 or higher.
96
+
97
+
```bash
98
+
npm i ox viem
99
+
```
100
+
</Step>
101
+
102
+
<Steptitle="Configure your wallet client">
103
+
Add the `dataSuffix` option when creating your wallet client. See the [viem wallet client docs](https://viem.sh/docs/clients/wallet) for more configuration options.
104
+
105
+
```ts client.ts
106
+
import { createWalletClient, http } from"viem";
107
+
import { base } from"viem/chains";
108
+
import { Attribution } from"ox/erc8021";
109
+
110
+
// Get your Builder Code from base.dev > Settings > Builder Codes
111
+
const DATA_SUFFIX =Attribution.toDataSuffix({
112
+
codes: ["YOUR-BUILDER-CODE"],
113
+
});
114
+
115
+
exportconst walletClient =createWalletClient({
116
+
chain: base,
117
+
transport: http(),
118
+
dataSuffix: DATA_SUFFIX,
119
+
});
120
+
```
121
+
</Step>
122
+
123
+
<Steptitle="Send transactions as usual">
124
+
All transactions sent through this client automatically include your Builder Code.
If you need to append the suffix on a per-transaction basis rather than at the client level, you can pass `dataSuffix` directly to the transaction.
142
+
143
+
<Tabs>
144
+
<Tabtitle="useSendTransaction">
145
+
```tsx App.tsx
146
+
import { useSendTransaction } from"wagmi";
147
+
import { parseEther } from"viem";
148
+
import { Attribution } from"ox/erc8021";
149
+
150
+
const DATA_SUFFIX =Attribution.toDataSuffix({
151
+
codes: ["YOUR-BUILDER-CODE"],
152
+
});
153
+
154
+
function App() {
155
+
const { sendTransaction } =useSendTransaction();
156
+
157
+
return (
158
+
<button
159
+
onClick={() =>
160
+
sendTransaction({
161
+
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
162
+
value: parseEther("0.01"),
163
+
dataSuffix: DATA_SUFFIX,
164
+
})
165
+
}
166
+
>
167
+
Send ETH
168
+
</button>
169
+
);
170
+
}
171
+
```
172
+
</Tab>
173
+
<Tabtitle="useSendCalls">
174
+
When using `useSendCalls`, pass the suffix via the `capabilities` object. This requires the connected wallet to support the `dataSuffix` capability.
175
+
176
+
```tsx App.tsx
177
+
import { useSendCalls } from"wagmi";
178
+
import { parseEther } from"viem";
179
+
import { Attribution } from"ox/erc8021";
180
+
181
+
const DATA_SUFFIX =Attribution.toDataSuffix({
182
+
codes: ["YOUR-BUILDER-CODE"],
183
+
});
184
+
185
+
function App() {
186
+
const { sendCalls } =useSendCalls();
187
+
188
+
return (
189
+
<button
190
+
onClick={() =>
191
+
sendCalls({
192
+
calls: [
193
+
{
194
+
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
195
+
value: parseEther("1"),
196
+
},
197
+
],
198
+
capabilities: {
199
+
dataSuffix: {
200
+
value: DATA_SUFFIX,
201
+
optional: true,
202
+
},
203
+
},
204
+
})
205
+
}
206
+
>
207
+
Send calls
208
+
</button>
209
+
);
210
+
}
211
+
```
212
+
</Tab>
213
+
</Tabs>
214
+
</Accordion>
215
+
216
+
### Verify attribution
217
+
218
+
To confirm your Builder Code is being appended correctly, see [How do I verify that my transaction was properly attributed?](/base-chain/builder-codes/builder-codes-faq#how-do-i-verify-that-my-transaction-was-properly-attributed) in the FAQ.
219
+
97
220
## For Wallet Developers
98
221
99
222
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.
100
223
101
224
<Steps>
102
-
<Steptitle="Support the dataSuffix Capability">
225
+
<Steptitle="Support the dataSuffix capability">
103
226
Your wallet should accept a `dataSuffix` object in the `capabilities` object of `wallet_sendCalls`.
104
227
105
-
```typescript lines
228
+
```typescript
106
229
typeDataSuffixCapability= {
107
230
value:`0x${string}`; // hex-encoded bytes provided by the app
108
231
optional?:boolean; // whether the capability is optional
@@ -111,14 +234,14 @@ Wallet providers need to support the `dataSuffix` capability to enable attributi
111
234
112
235
</Step>
113
236
114
-
<Step title="Append Suffix to Calldata">
237
+
<Step title="Append suffix to calldata">
115
238
When constructing the transaction or User Operation, extract the `dataSuffix` and append it to the calldata.
116
239
117
240
<Tabs>
118
241
<Tab title="EOA Transactions">
119
242
Append to `tx.data`.
120
243
121
-
```typescriptlines
244
+
```typescript
122
245
// Minimal example for EOA
123
246
function applySuffixToEOA(tx, capabilities) {
124
247
const suffix =capabilities.dataSuffix?.value
@@ -135,7 +258,7 @@ Wallet providers need to support the `dataSuffix` capability to enable attributi
135
258
<Tabtitle="ERC-4337 User Operations">
136
259
Append to `userOp.callData` (not the transaction-level calldata).
137
260
138
-
```typescript lines
261
+
```typescript
139
262
// Minimal example for ERC-4337
140
263
function applySuffixToUserOp(userOp, capabilities) {
141
264
const suffix =capabilities.dataSuffix?.value
@@ -152,11 +275,11 @@ Wallet providers need to support the `dataSuffix` capability to enable attributi
152
275
</Tabs>
153
276
154
277
</Step>
155
-
<Steptitle="(Optional) Add Wallet Attribution">
156
-
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.
278
+
<Steptitle="Add wallet attribution (optional)">
279
+
Wallets may also include their own attribution code (their own ERC-8021 suffix) by prepending the wallet's suffix before the app's.
157
280
158
-
***No interaction required with apps:** The wallet handles this independently.
@@ -191,7 +314,7 @@ Builder codes work with the [Base-Solana bridge](/base-chain/quickstart/base-sol
191
314
192
315
</Step>
193
316
194
-
<Steptitle="Attach to Bridge Message">
317
+
<Steptitle="Attach to bridge message">
195
318
Set `to = BRIDGE_CAMPAIGN_ADDRESS` and attach a call to `Flywheel.send`.
196
319
197
320
<Tabs>
@@ -251,7 +374,7 @@ Builder codes work with the [Base-Solana bridge](/base-chain/quickstart/base-sol
251
374
</Tabs>
252
375
253
376
</Step>
254
-
<Steptitle="Learn More: A Full Implementation Example">
377
+
<Steptitle="Learn more: A full implementation example">
255
378
[Terminally Onchain](https://terminallyonchain.com/) is a production Next.js app that exposes the bridge via a command terminal UI. Users connect a Solana wallet, type commands such as to bridge and call a contract on Base:
256
379
257
380
You can use [Terminally Onchain](https://terminallyonchain.com/) to test bridge transactions with Builder Codes like so:
0 commit comments