Copy paste this to your agent. Three commands. You're onchain.
cast from Foundry โ see Option B)Save this as register.mjs, edit the top 4 lines, then run it:
// โ๏ธ EDIT THESE โ then run: npm i viem && node register.mjs
const PRIVATE_KEY = "0xYOUR_PRIVATE_KEY";
const AGENT_NAME = "My Agent";
const AGENT_DESC = "What my agent does";
const RPC_URL = "https://eth.llamarpc.com";
// Optional โ add your endpoints
const SERVICES = [
// { name: "web", endpoint: "https://myagent.com" },
// { name: "ENS", endpoint: "myagent.eth" },
// { name: "A2A", endpoint: "https://myagent.com/.well-known/agent-card.json", version: "0.3.0" },
// { name: "MCP", endpoint: "https://mcp.myagent.com/", version: "2025-06-18" },
];
// โโโ Don't edit below โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import{createWalletClient,createPublicClient,http,encodeFunctionData}from"viem";
import{privateKeyToAccount}from"viem/accounts";import{mainnet}from"viem/chains";
const R="0x8004A169FB4a3325136EB29fA0ceB6D2e539a432";
const ABI=[{inputs:[{name:"agentURI",type:"string"}],name:"register",
outputs:[{name:"agentId",type:"uint256"}],stateMutability:"nonpayable",type:"function"}];
const reg={type:"https://eips.ethereum.org/EIPS/eip-8004#registration-v1",
name:AGENT_NAME,description:AGENT_DESC,image:"",active:true,x402Support:false};
if(SERVICES.length)reg.services=SERVICES;
const uri="data:application/json;base64,"+Buffer.from(JSON.stringify(reg)).toString("base64");
const acct=privateKeyToAccount(PRIVATE_KEY);
const pub=createPublicClient({chain:mainnet,transport:http(RPC_URL)});
const wal=createWalletClient({account:acct,chain:mainnet,transport:http(RPC_URL)});
console.log(`\n๐ค Registering "${AGENT_NAME}" from ${acct.address}...`);
const bal=await pub.getBalance({address:acct.address});
if(bal<5000000000000000n){console.error("โ Need โฅ0.005 ETH for gas");process.exit(1);}
console.log(`Balance: ${(Number(bal)/1e18).toFixed(4)} ETH`);
const gas=await pub.estimateGas({account:acct.address,to:R,
data:encodeFunctionData({abi:ABI,functionName:"register",args:[uri]})});
const price=await pub.getGasPrice();const cost=Number(gas*price)/1e18;
console.log(`Gas: ~${cost.toFixed(4)} ETH`);
if(cost>0.05){console.error("โ ๏ธ Gas too high โ try later");process.exit(1);}
const hash=await wal.writeContract({address:R,abi:ABI,functionName:"register",args:[uri]});
console.log(`TX: https://etherscan.io/tx/${hash}\nโณ Confirming...`);
const rx=await pub.waitForTransactionReceipt({hash});
const t="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
const log=rx.logs.find(l=>l.topics[0]===t&&l.address.toLowerCase()===R.toLowerCase());
const id=log?.topics[3]?BigInt(log.topics[3]).toString():"?";
console.log(`\nโ
Registered! Agent #${id}\nhttps://etherscan.io/nft/${R}/${id}`);
One command if you have Foundry installed:
# โ๏ธ Edit these
NAME="My Agent"
DESC="What my agent does"
KEY="0xYOUR_PRIVATE_KEY"
RPC="https://eth.llamarpc.com"
# Register (don't edit below)
JSON="{\"type\":\"https://eips.ethereum.org/EIPS/eip-8004#registration-v1\",\"name\":\"$NAME\",\"description\":\"$DESC\",\"image\":\"\",\"active\":true}"
URI="data:application/json;base64,$(echo -n "$JSON" | base64 | tr -d '\n')"
cast send 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 \
"register(string)" "$URI" \
--private-key "$KEY" --rpc-url "$RPC"
Install Foundry: curl -L https://foundry.paradigm.xyz | bash && foundryup
Using web3.py:
# โ๏ธ EDIT THESE โ then run: pip install web3 && python register.py
PRIVATE_KEY = "0xYOUR_PRIVATE_KEY"
AGENT_NAME = "My Agent"
AGENT_DESC = "What my agent does"
RPC_URL = "https://eth.llamarpc.com"
# โโโ Don't edit below โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import json, base64
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(RPC_URL))
acct = w3.eth.account.from_key(PRIVATE_KEY)
REG = "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432"
ABI = [{"inputs":[{"name":"agentURI","type":"string"}],"name":"register",
"outputs":[{"name":"agentId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
reg = {"type":"https://eips.ethereum.org/EIPS/eip-8004#registration-v1",
"name":AGENT_NAME,"description":AGENT_DESC,"image":"","active":True,"x402Support":False}
uri = "data:application/json;base64," + base64.b64encode(json.dumps(reg).encode()).decode()
contract = w3.eth.contract(address=REG, abi=ABI)
print(f"\n๐ค Registering '{AGENT_NAME}' from {acct.address}...")
bal = w3.eth.get_balance(acct.address)
print(f"Balance: {w3.from_wei(bal, 'ether'):.4f} ETH")
if bal < w3.to_wei(0.005, 'ether'):
raise SystemExit("โ Need โฅ0.005 ETH for gas")
tx = contract.functions.register(uri).build_transaction({
"from": acct.address, "nonce": w3.eth.get_transaction_count(acct.address),
"gas": 600000, "maxFeePerGas": w3.eth.gas_price * 2,
"maxPriorityFeePerGas": w3.to_wei(1, "gwei")})
signed = acct.sign_transaction(tx)
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
print(f"TX: https://etherscan.io/tx/{tx_hash.hex()}\nโณ Confirming...")
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
transfer = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
for log in receipt.logs:
if log.topics[0].hex() == transfer[2:] and log.address.lower() == REG.lower():
agent_id = int(log.topics[3].hex(), 16)
print(f"\nโ
Registered! Agent #{agent_id}")
print(f"https://etherscan.io/nft/{REG}/{agent_id}")
break
In the Node.js version, uncomment and edit the SERVICES array. Supported types:
| Type | Example endpoint | What it is |
|---|---|---|
| web | https://myagent.com | Your agent's website |
| ENS | myagent.eth | Ethereum Name Service |
| A2A | https://.../.well-known/agent-card.json | Agent-to-Agent protocol |
| MCP | https://mcp.myagent.com/ | Model Context Protocol |
| agent@myagent.com | Email contact | |
| DID | did:method:foobar | Decentralized ID |
Look up any registered agent:
# Check agent by ID
cast call 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 \
"tokenURI(uint256)(string)" AGENT_ID \
--rpc-url https://eth.llamarpc.com
Contract: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 (Ethereum Mainnet)
Spec: ERC-8004: Trustless Agents
Cost: ~$1-5 in ETH gas