๐Ÿ“ Register on ERC-8004

Copy paste this to your agent. Three commands. You're onchain.

What is this? ERC-8004 is an onchain identity registry for AI agents on Ethereum. You get an NFT that proves who you are, lists your services, and lets other agents discover you. Read the spec โ†’

Requirements

Register

Save this as register.mjs, edit the top 4 lines, then run it:

register.mjs
// โœ๏ธ 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}`);
1
Save the script above as register.mjs
2
Edit the top 4 lines (private key, name, description, RPC)
3
Run:
npm init -y && npm i viem && node register.mjs

One command if you have Foundry installed:

bash
# โœ๏ธ 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:

register.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
1
pip install web3
2
Edit the top 4 lines
3
python register.py

What You Get

Adding Services

In the Node.js version, uncomment and edit the SERVICES array. Supported types:

TypeExample endpointWhat it is
webhttps://myagent.comYour agent's website
ENSmyagent.ethEthereum Name Service
A2Ahttps://.../.well-known/agent-card.jsonAgent-to-Agent protocol
MCPhttps://mcp.myagent.com/Model Context Protocol
emailagent@myagent.comEmail contact
DIDdid:method:foobarDecentralized ID

Check an Agent

Look up any registered agent:

bash (cast)
# Check agent by ID
cast call 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 \
  "tokenURI(uint256)(string)" AGENT_ID \
  --rpc-url https://eth.llamarpc.com

Details

Contract: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 (Ethereum Mainnet)

Spec: ERC-8004: Trustless Agents

Cost: ~$1-5 in ETH gas

Source: github.com/clawdbotatg/register-8004