|
2 | 2 | title: "Get a Builder Code for Your Agent" |
3 | 3 | description: "Register your agent on Base.dev and append a Builder Code to every transaction to measure onchain activity." |
4 | 4 | keywords: ["builder code", "Base.dev", "ERC-8021", "attribution", "onchain activity", "agent attribution", "dataSuffix", "builder codes", "Base builder codes", "agent onchain"] |
| 5 | +tag: "NEW" |
5 | 6 | --- |
6 | 7 |
|
7 | 8 | Base.dev is the canonical registry for agents on Base. A Builder Code ties every transaction your agent sends to your identity in that registry, giving you verifiable onchain attribution and access to analytics and leaderboard features. |
@@ -58,88 +59,6 @@ Follow the instructions to: |
58 | 59 | 2. Return the builder code |
59 | 60 | 3. Show me how to append the builder code to my transactions using ERC-8021 |
60 | 61 | ``` |
61 | | - |
62 | | ---- |
63 | | - |
64 | | -## Append your Builder Code to transactions |
65 | | - |
66 | | -Once you have a Builder Code, append it to every onchain transaction so Base can measure your agent's activity. This uses the [ERC-8021 standard](/base-chain/quickstart/builder-codes). |
67 | | - |
68 | | -<CodeGroup> |
69 | | - |
70 | | -```typescript viem lines expandable |
71 | | -import { createWalletClient, http } from "viem"; |
72 | | -import { base } from "viem/chains"; |
73 | | -import { privateKeyToAccount } from "viem/accounts"; |
74 | | -import { Attribution } from "ox/erc8021"; |
75 | | - |
76 | | -const DATA_SUFFIX = Attribution.toDataSuffix({ |
77 | | - codes: ["bc_a1b2c3d4"], |
78 | | -}); |
79 | | - |
80 | | -const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`); |
81 | | - |
82 | | -export const walletClient = createWalletClient({ |
83 | | - account, |
84 | | - chain: base, |
85 | | - transport: http(), |
86 | | - dataSuffix: DATA_SUFFIX, |
87 | | -}); |
88 | | - |
89 | | -// All transactions sent through this client automatically include your Builder Code |
90 | | -const hash = await walletClient.sendTransaction({ |
91 | | - to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", |
92 | | - value: parseEther("0.1"), |
93 | | -}); |
94 | | -``` |
95 | | - |
96 | | -```javascript ethers.js lines expandable |
97 | | -import { Attribution } from 'ox/erc8021'; |
98 | | -import { ethers } from 'ethers'; |
99 | | - |
100 | | -const builderCode = 'bc_a1b2c3d4'; |
101 | | -const suffix = Attribution.toDataSuffix({ codes: [builderCode] }); |
102 | | - |
103 | | -const provider = new ethers.JsonRpcProvider('https://mainnet.base.org'); |
104 | | -const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); |
105 | | - |
106 | | -const tx = { |
107 | | - to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', |
108 | | - value: ethers.parseEther('0.1'), |
109 | | - data: suffix, // or append to existing calldata |
110 | | -}; |
111 | | - |
112 | | -const txResponse = await wallet.sendTransaction(tx); |
113 | | -``` |
114 | | - |
115 | | -```python web3.py lines expandable |
116 | | -from web3 import Web3 |
117 | | -from eth_account import Account |
118 | | -from ox.erc8021 import Attribution |
119 | | - |
120 | | -builder_code = 'bc_a1b2c3d4' |
121 | | -suffix = Attribution.to_data_suffix(codes=[builder_code]) |
122 | | - |
123 | | -w3 = Web3(Web3.HTTPProvider('https://mainnet.base.org')) |
124 | | -account = Account.from_key(os.environ['PRIVATE_KEY']) |
125 | | - |
126 | | -tx = { |
127 | | - 'from': account.address, |
128 | | - 'to': '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', |
129 | | - 'value': Web3.to_wei(0.1, 'ether'), |
130 | | - 'data': suffix, # or append to existing calldata |
131 | | - 'nonce': w3.eth.get_transaction_count(account.address), |
132 | | - 'gas': 21000, |
133 | | - 'gasPrice': w3.eth.gas_price, |
134 | | - 'chainId': 8453, |
135 | | -} |
136 | | - |
137 | | -signed = account.sign_transaction(tx) |
138 | | -tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction) |
139 | | -``` |
140 | | - |
141 | | -</CodeGroup> |
142 | | - |
143 | 62 | --- |
144 | 63 |
|
145 | 64 | ## What happens next |
|
0 commit comments