|
| 1 | +--- |
| 2 | +title: "Builder Codes for App Developers" |
| 3 | +sidebarTitle: "For App Developers" |
| 4 | +description: "Integrate Builder Codes into your app using Wagmi or Viem to attribute onchain activity." |
| 5 | +--- |
| 6 | + |
| 7 | +## Automatic Attribution on Base |
| 8 | + |
| 9 | +Once your app is registered on [base.dev](http://base.dev/), the Base App will auto-append your 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. |
| 10 | + |
| 11 | +## Integrating Outside the Base App |
| 12 | + |
| 13 | +If users also access your app on the web or through other clients, you'll need to integrate the `dataSuffix` parameter to capture that activity. |
| 14 | + |
| 15 | +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. The recommended approach is to configure `dataSuffix` at the client level, which appends your Builder Code to all transactions. |
| 16 | + |
| 17 | +<Tip> |
| 18 | + You can find your code anytime under **Settings** → **Builder Code**. |
| 19 | +</Tip> |
| 20 | + |
| 21 | +## Quick Setup with Wagmi |
| 22 | + |
| 23 | +<Steps> |
| 24 | + <Step title="Install Dependencies"> |
| 25 | + Install the required packages. Requires viem version `2.45.0` or higher. |
| 26 | + |
| 27 | + ```bash |
| 28 | + npm i ox wagmi viem |
| 29 | + ``` |
| 30 | + </Step> |
| 31 | + |
| 32 | + <Step title="Configure Your Wagmi Client"> |
| 33 | + Add the `dataSuffix` option to your Wagmi config. This automatically appends your Builder Code to all transactions. |
| 34 | + |
| 35 | + ```ts config.ts |
| 36 | + import { createConfig, http } from "wagmi"; |
| 37 | + import { base } from "wagmi/chains"; |
| 38 | + import { Attribution } from "ox/erc8021"; |
| 39 | + |
| 40 | + // Get your Builder Code from base.dev > Settings > Builder Codes |
| 41 | + const DATA_SUFFIX = Attribution.toDataSuffix({ |
| 42 | + codes: ["YOUR-BUILDER-CODE"], |
| 43 | + }); |
| 44 | + |
| 45 | + export const config = createConfig({ |
| 46 | + chains: [base], |
| 47 | + transports: { |
| 48 | + [base.id]: http(), |
| 49 | + }, |
| 50 | + dataSuffix: DATA_SUFFIX, |
| 51 | + }); |
| 52 | + ``` |
| 53 | + </Step> |
| 54 | + |
| 55 | + <Step title="Use Wagmi Hooks as Usual"> |
| 56 | + 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`. |
| 57 | + |
| 58 | + ```tsx App.tsx |
| 59 | + import { useSendTransaction } from "wagmi"; |
| 60 | + import { parseEther } from "viem"; |
| 61 | + |
| 62 | + function SendButton() { |
| 63 | + const { sendTransaction } = useSendTransaction(); |
| 64 | + |
| 65 | + return ( |
| 66 | + <button |
| 67 | + onClick={() => |
| 68 | + sendTransaction({ |
| 69 | + to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", |
| 70 | + value: parseEther("0.01"), |
| 71 | + }) |
| 72 | + } |
| 73 | + > |
| 74 | + Send ETH |
| 75 | + </button> |
| 76 | + ); |
| 77 | + } |
| 78 | + ``` |
| 79 | + </Step> |
| 80 | +</Steps> |
| 81 | + |
| 82 | +## Quick Setup with Viem |
| 83 | + |
| 84 | +<Steps> |
| 85 | + <Step title="Install Dependencies"> |
| 86 | + Install the required packages. Requires viem version `2.45.0` or higher. |
| 87 | + |
| 88 | + ```bash |
| 89 | + npm i ox viem |
| 90 | + ``` |
| 91 | + </Step> |
| 92 | + |
| 93 | + <Step title="Configure Your Wallet Client"> |
| 94 | + 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. |
| 95 | + |
| 96 | + ```ts client.ts |
| 97 | + import { createWalletClient, http } from "viem"; |
| 98 | + import { base } from "viem/chains"; |
| 99 | + import { Attribution } from "ox/erc8021"; |
| 100 | + |
| 101 | + // Get your Builder Code from base.dev > Settings > Builder Codes |
| 102 | + const DATA_SUFFIX = Attribution.toDataSuffix({ |
| 103 | + codes: ["YOUR-BUILDER-CODE"], |
| 104 | + }); |
| 105 | + |
| 106 | + export const walletClient = createWalletClient({ |
| 107 | + chain: base, |
| 108 | + transport: http(), |
| 109 | + dataSuffix: DATA_SUFFIX, |
| 110 | + }); |
| 111 | + ``` |
| 112 | + </Step> |
| 113 | + |
| 114 | + <Step title="Send Transactions as Usual"> |
| 115 | + All transactions sent through this client automatically include your Builder Code. |
| 116 | + |
| 117 | + ```ts |
| 118 | + import { parseEther } from "viem"; |
| 119 | + import { walletClient } from "./client"; |
| 120 | + |
| 121 | + const hash = await walletClient.sendTransaction({ |
| 122 | + to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", |
| 123 | + value: parseEther("0.01"), |
| 124 | + }); |
| 125 | + ``` |
| 126 | + </Step> |
| 127 | +</Steps> |
| 128 | + |
| 129 | +## Legacy: Per-Transaction Approach |
| 130 | + |
| 131 | +<Accordion title="Appending dataSuffix Per-Transaction"> |
| 132 | + 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. |
| 133 | + |
| 134 | + <Tabs> |
| 135 | + <Tab title="useSendTransaction"> |
| 136 | + ```tsx App.tsx |
| 137 | + import { useSendTransaction } from "wagmi"; |
| 138 | + import { parseEther } from "viem"; |
| 139 | + import { Attribution } from "ox/erc8021"; |
| 140 | + |
| 141 | + const DATA_SUFFIX = Attribution.toDataSuffix({ |
| 142 | + codes: ["YOUR-BUILDER-CODE"], |
| 143 | + }); |
| 144 | + |
| 145 | + function App() { |
| 146 | + const { sendTransaction } = useSendTransaction(); |
| 147 | + |
| 148 | + return ( |
| 149 | + <button |
| 150 | + onClick={() => |
| 151 | + sendTransaction({ |
| 152 | + to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", |
| 153 | + value: parseEther("0.01"), |
| 154 | + dataSuffix: DATA_SUFFIX, |
| 155 | + }) |
| 156 | + } |
| 157 | + > |
| 158 | + Send ETH |
| 159 | + </button> |
| 160 | + ); |
| 161 | + } |
| 162 | + ``` |
| 163 | + </Tab> |
| 164 | + <Tab title="useSendCalls"> |
| 165 | + When using `useSendCalls`, pass the suffix via the `capabilities` object. This requires the connected wallet to support the `dataSuffix` capability. |
| 166 | + |
| 167 | + ```tsx App.tsx |
| 168 | + import { useSendCalls } from "wagmi"; |
| 169 | + import { parseEther } from "viem"; |
| 170 | + import { Attribution } from "ox/erc8021"; |
| 171 | + |
| 172 | + const DATA_SUFFIX = Attribution.toDataSuffix({ |
| 173 | + codes: ["YOUR-BUILDER-CODE"], |
| 174 | + }); |
| 175 | + |
| 176 | + function App() { |
| 177 | + const { sendCalls } = useSendCalls(); |
| 178 | + |
| 179 | + return ( |
| 180 | + <button |
| 181 | + onClick={() => |
| 182 | + sendCalls({ |
| 183 | + calls: [ |
| 184 | + { |
| 185 | + to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", |
| 186 | + value: parseEther("1"), |
| 187 | + }, |
| 188 | + ], |
| 189 | + capabilities: { |
| 190 | + dataSuffix: { |
| 191 | + value: DATA_SUFFIX, |
| 192 | + optional: true, |
| 193 | + }, |
| 194 | + }, |
| 195 | + }) |
| 196 | + } |
| 197 | + > |
| 198 | + Send calls |
| 199 | + </button> |
| 200 | + ); |
| 201 | + } |
| 202 | + ``` |
| 203 | + </Tab> |
| 204 | + </Tabs> |
| 205 | +</Accordion> |
| 206 | + |
| 207 | +## Verify Attribution |
| 208 | + |
| 209 | +To confirm your Builder Code is being appended correctly: |
| 210 | + |
| 211 | +**1. Check base.dev** |
| 212 | + |
| 213 | +- Visit [base.dev](https://base.dev) |
| 214 | +- Select **Onchain** from the transaction type dropdown |
| 215 | +- Under the Total Transactions section, attribution counts increment when transactions with your code are processed |
| 216 | + |
| 217 | +**2. Use a Block Explorer (Basescan, Etherscan, etc.)** |
| 218 | + |
| 219 | +- Find your transaction hash |
| 220 | +- View the input data field |
| 221 | +- Verify the last 16 bytes are the `8021` repeating |
| 222 | +- Decode the suffix to confirm your Builder Code is present |
| 223 | + |
| 224 | +**3. Open Source Tools** |
| 225 | + |
| 226 | +- Use the [Builder Code Validation](https://builder-code-checker.vercel.app/) tool |
| 227 | +- Select transaction type |
| 228 | +- Enter the transaction or UserOperation hash |
| 229 | +- Click the **Check Attribution** button |
0 commit comments