钱包提供商的 Builder Codes#
如果你正在构建钱包,并希望为运行在 X Layer 上的应用支持 ERC-8021 归因,请按照以下方式实现。
实现方式#
1. 支持 dataSuffix 能力#
你的钱包应在 wallet_sendCalls 的 capabilities 字段中接受一个 dataSuffix 对象。
typescript
type DataSuffixCapability = {
value: `0x${string}`; // hex-encoded bytes provided by the app
optional?: boolean; // whether the capability is optional
}
2. 将后缀附加到 Calldata#
在构建交易时,提取 dataSuffix 并将其附加到 calldata 末尾。
EOA 交易 —— 附加到 tx.data,原生转账默认使用 0x:
typescript
// Minimal example for EOA
function applySuffixToEOA(tx, capabilities) {
const suffix = capabilities.dataSuffix?.value
if (!suffix) return tx
const data = tx.data ?? "0x"
return {
...tx,
// Works for both contract calls and native token transfers
data: data + suffix.slice(2)
}
}
ERC-4337 用户操作(User Operations) —— 暂不支持。
3. 添加钱包归因(可选)#
钱包可通过在应用后缀之前附加钱包自身的后缀来包含其 Builder Code。
- 无需与应用交互: 钱包独立处理此操作。
- 多编码支持: ERC-8021 原生支持多个归因编码。
typescript
finalSuffix = walletSuffix + appSuffix
这样可以确保应用和钱包都能在 X Layer 上获得链上归因。
获取你的 Builder Code: 前往 OKX 开发者门户,验证你的地址,然后在 Builder Code 页面创建你的 Builder Code。
