adding-builder-codes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdding Builder Codes
添加Builder Codes
Integrate Base Builder Codes into an onchain application. Builder Codes append an ERC-8021 attribution suffix to transaction calldata so Base can attribute activity to your app and you can earn referral fees. No smart contract changes required.
将Base Builder Codes集成到链上应用中。Builder Codes会在交易调用数据后附加ERC-8021归因后缀,这样Base就能将活动归因到你的应用,你也可以赚取推荐费。无需修改智能合约。
When to Use This Skill
何时使用此技能
Use this skill when a developer asks to:
- "Add builder codes to my application"
- "How do I append a builder code to my transactions?"
- "I want to earn referral fees on Base transactions"
- "Integrate builder codes"
- Set up transaction attribution on Base
当开发者提出以下需求时,使用此技能:
- "为我的应用添加builder codes"
- "如何为我的交易附加builder code?"
- "我想在Base交易中赚取推荐费"
- "集成builder codes"
- 在Base上设置交易归因
Prerequisites
前提条件
- A Builder Code from base.dev > Settings > Builder Codes
- The library for generating ERC-8021 suffixes:
oxnpm install ox
- 从base.dev > 设置 > Builder Codes获取的Builder Code
- 用于生成ERC-8021后缀的库:
oxnpm install ox
Integration Workflow
集成流程
Copy this checklist and track progress:
Builder Codes Integration:
- [ ] Step 1: Detect framework (Required First Step)
- [ ] Step 2: Install dependencies
- [ ] Step 3: Generate the dataSuffix constant
- [ ] Step 4: Apply attribution (framework-specific)
- [ ] Step 5: Verify attribution is working复制此清单并跟踪进度:
Builder Codes Integration:
- [ ] Step 1: Detect framework (Required First Step)
- [ ] Step 2: Install dependencies
- [ ] Step 3: Generate the dataSuffix constant
- [ ] Step 4: Apply attribution (framework-specific)
- [ ] Step 5: Verify attribution is workingFramework Detection (Required First Step)
框架检测(第一步,必须执行)
Before implementing, determine the framework in use.
在实施前,先确定所使用的框架。
1. Read package.json and scan source files
1. 读取package.json并扫描源文件
bash
undefinedbash
undefinedCheck for framework dependencies
Check for framework dependencies
grep -E "wagmi|@privy-io/react-auth|viem|ethers" package.json
grep -E "wagmi|@privy-io/react-auth|viem|ethers" package.json
Check for smart wallet / account abstraction usage
Check for smart wallet / account abstraction usage
grep -rn "useSendCalls|sendCalls|ERC-4337|useSmartWallets" src/
grep -rn "useSendCalls|sendCalls|ERC-4337|useSmartWallets" src/
Check for EOA transaction patterns
Check for EOA transaction patterns
grep -rn "useSendTransaction|sendTransaction|writeContract|useWriteContract" src/
grep -rn "useSendTransaction|sendTransaction|writeContract|useWriteContract" src/
Check Privy version if present
Check Privy version if present
grep "@privy-io/react-auth" package.json
undefinedgrep "@privy-io/react-auth" package.json
undefined2. Classify into one framework
2. 归类到对应框架
| Framework | Detection Signal |
|---|---|
| |
| |
| |
| |
Priority order if multiple are detected: Privy > Wagmi > Viem > Standard RPC
| 框架 | 检测信号 |
|---|---|
| package.json或导入语句中存在 |
| package.json或导入语句中存在 |
| package.json中存在 |
| 检测到 |
如果检测到多个框架,优先级顺序为:Privy > Wagmi > Viem > 标准RPC
3. Confirm with user
3. 与用户确认
Before proceeding, confirm the detected framework:
"I detected you are using [Framework]. I'll implement builder codes using the [Framework] approach — does that sound right?"
Wait for user confirmation before implementing.
在继续之前,确认检测到的框架:
"我检测到你正在使用[Framework]。我将采用[Framework]方案来实现builder codes——这样可以吗?"
等待用户确认后再进行实施。
Implementation Path
实施路径
- Privy (v3.13.0+) → See references/privy.md
@privy-io/react-auth - Wagmi (without Privy) → See references/wagmi.md
- Viem only (no React framework) → See references/viem.md
- Standard RPC (ethers.js or raw ) → See references/rpc.md
window.ethereum
- Privy(v3.13.0+)→ 查看references/privy.md
@privy-io/react-auth - Wagmi(无Privy)→ 查看references/wagmi.md
- 仅Viem(无React框架)→ 查看references/viem.md
- 标准RPC(ethers.js或原生)→ 查看references/rpc.md
window.ethereum
Step 2: Install dependencies
步骤2:安装依赖
bash
npm install oxRequires for Wagmi/Viem paths. Privy requires .
viem >= 2.45.0@privy-io/react-auth >= 3.13.0bash
npm install oxWagmi/Viem路径需要。Privy需要。
viem >= 2.45.0@privy-io/react-auth >= 3.13.0Step 3: Generate the dataSuffix constant
步骤3:生成dataSuffix常量
Create a shared constant (e.g., or ):
src/lib/attribution.tssrc/constants/builderCode.tstypescript
import { Attribution } from "ox/erc8021";
export const DATA_SUFFIX = Attribution.toDataSuffix({
codes: ["YOUR-BUILDER-CODE"], // Replace with your code from base.dev
});创建一个共享常量(例如或):
src/lib/attribution.tssrc/constants/builderCode.tstypescript
import { Attribution } from "ox/erc8021";
export const DATA_SUFFIX = Attribution.toDataSuffix({
codes: ["YOUR-BUILDER-CODE"], // 替换为你从base.dev获取的代码
});Step 4: Apply attribution
步骤4:应用归因
Follow the framework-specific guide:
遵循框架特定指南:
Privy Implementation
Privy实施
See references/privy.md — plugin-based, one config change required.
查看references/privy.md —— 基于插件,只需修改一处配置。
Wagmi Implementation
Wagmi实施
See references/wagmi.md — add to Wagmi client config.
dataSuffix查看references/wagmi.md —— 在Wagmi客户端配置中添加。
dataSuffixViem Implementation
Viem实施
See references/viem.md — add to wallet client.
dataSuffix查看references/viem.md —— 在钱包客户端中添加。
dataSuffixStandard RPC Implementation
标准RPC实施
See references/rpc.md — append to transaction data for ethers.js or raw .
DATA_SUFFIXwindow.ethereumPreferred approach: Configure at the client level so all transactions are automatically attributed. Only use the per-transaction approach if you need conditional attribution.
For Smart Wallets (EIP-5792 ): See references/smart-wallets.md — pass via .
sendCallscapabilities查看references/rpc.md —— 为ethers.js或原生的交易数据附加。
window.ethereumDATA_SUFFIX推荐方案:在客户端级别进行配置,这样所有交易都会自动被归因。仅当需要条件性归因时,才使用逐交易配置的方案。
对于智能钱包(EIP-5792 ):查看references/smart-wallets.md —— 通过传递。
sendCallscapabilitiesStep 5: Verify attribution
步骤5:验证归因
- base.dev: Check Onchain > Total Transactions for attribution counts
- Block explorer: Find tx hash, view input data, confirm last 16 bytes are repeating
8021 - Validation tool: Use builder-code-checker.vercel.app
- base.dev:查看Onchain > Total Transactions中的归因统计
- 区块浏览器:找到交易哈希,查看输入数据,确认最后16字节是重复的
8021 - 验证工具:使用builder-code-checker.vercel.app
Key Facts
关键事实
- Builder Codes are ERC-721 NFTs minted on Base
- The suffix is appended to calldata; smart contracts ignore it (no upgrades needed)
- Gas cost is negligible: 16 gas per non-zero byte
- Analytics on base.dev currently support Smart Account (AA) transactions; EOA support is coming (attribution data is preserved)
- The plugin in Privy appends to all chains, not just Base. If chain-specific behavior is needed, contact Privy
dataSuffix - Privy's plugin is NOT yet supported with
dataSuffixadapter@privy-io/wagmi
- Builder Codes是在Base上铸造的ERC-721 NFT
- 后缀附加在调用数据后;智能合约会忽略它(无需升级)
- Gas成本可忽略不计:每个非零字节消耗16 gas
- base.dev上的分析目前支持智能账户(AA)交易;EOA支持即将推出(归因数据已保留)
- Privy中的插件会为所有链附加后缀,而不仅仅是Base。如果需要链特定行为,请联系Privy
dataSuffix - Privy的插件目前尚不支持
dataSuffix适配器@privy-io/wagmi
Finding Transaction Call Sites
查找交易调用位置
When retrofitting an existing project, search for these patterns:
bash
undefined在改造现有项目时,搜索以下模式:
bash
undefinedReact hooks (Wagmi)
React hooks (Wagmi)
grep -rn "useSendTransaction|useSendCalls|useWriteContract|useContractWrite" src/
grep -rn "useSendTransaction|useSendCalls|useWriteContract|useContractWrite" src/
Viem client calls
Viem client calls
grep -rn "sendTransaction|writeContract|sendRawTransaction" src/
grep -rn "sendTransaction|writeContract|sendRawTransaction" src/
Privy embedded wallet calls
Privy embedded wallet calls
grep -rn "sendTransaction|signTransaction" src/
grep -rn "sendTransaction|signTransaction" src/
ethers.js
ethers.js
grep -rn "signer.sendTransaction|contract.connect" src/
grep -rn "signer.sendTransaction|contract.connect" src/
Raw window.ethereum
Raw window.ethereum
grep -rn "window.ethereum|eth_sendTransaction" src/
For client-level integration (Wagmi/Viem/Privy), you typically only need to modify the config file — individual transaction call sites remain unchanged.grep -rn "window.ethereum|eth_sendTransaction" src/
对于客户端级别集成(Wagmi/Viem/Privy),通常只需修改配置文件——无需更改单个交易调用位置。