Setting the file. One moment.
Subchapter 4.14
references/builder-codes/viem.mdMarkdown2 KBView on GitHub
Configure dataSuffix on your wallet client to automatically append your Builder Code to all transactions.
viem >= 2.45.0ox library installed// client.ts
import { createWalletClient, http } from "viem";
import { base } from "viem/chains";
import { Attribution } from "ox/erc8021";
const DATA_SUFFIX = Attribution.toDataSuffix({
codes: ["YOUR-BUILDER-CODE"],
});
export const walletClient = createWalletClient({
chain: base,
transport: http(),
dataSuffix: DATA_SUFFIX,
});All transactions through this client are automatically attributed:
import { parseEther } from "viem";
import { walletClient } from "./client";
const hash = await walletClient.sendTransaction({
to: "0x...",
value: parseEther("0.01"),
});const hash = await walletClient.sendTransaction({
to: "0x...",
value: parseEther("0.01"),
dataSuffix: DATA_SUFFIX,
});For backend agents or bots using viem directly with a private key:
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { Attribution } from "ox/erc8021";
const DATA_SUFFIX = Attribution.toDataSuffix({
codes: ["YOUR-BUILDER-CODE"],
});
const account = privateKeyToAccount("0x...");
const walletClient = createWalletClient({
account,
chain: base,
transport: http(),
dataSuffix: DATA_SUFFIX,
});This is the typical pattern for AI agent wallets that transact on behalf of users.