---
name: agent-8004-register
description: Give an AI agent an on-chain identity with ERC-8004 / TRC-8004 — write the registration file, host it, and call register(tokenURI) on the Identity Registry. Use when the user wants their agent to be discoverable, to publish its endpoints and payment wallet, or to collect reputation.
---

# Register an agent with 8004

## 1. Gather details

Ask for (or infer from the project): agent name, one-line description, image URL, public endpoints (MCP, A2A agent card, web), the wallet that receives payments, the target chain, and which Identity Registry address to use on that chain. Do not guess registry addresses — ask the user or read them from the official 8004 deployments list.

## 2. Write the registration file

```json
{
  "type": "https://eips.ethereum.org/EIPS/eip-8004#registration-v1",
  "name": "AgentName",
  "description": "What the agent does, who it is for, and how it charges.",
  "image": "https://…/avatar.png",
  "endpoints": [
    { "name": "MCP", "endpoint": "https://…/mcp" },
    { "name": "A2A", "endpoint": "https://…/.well-known/agent-card.json" },
    { "name": "agentWallet", "endpoint": "eip155:<chainId>:0xWallet" }
  ],
  "registrations": [],
  "supportedTrust": ["reputation"]
}
```

Keep `registrations` empty until the agent ID is known, then add `{ "agentId": <id>, "agentRegistry": "eip155:<chainId>:<registry>" }` and re-upload.

## 3. Host it

Use a stable URL the user controls: HTTPS on their domain (e.g. `/.well-known/agent-registration.json`) or IPFS (`ipfs://…`). The content must stay reachable — the token URI is how others find the agent.

## 4. Register on-chain

Identity Registry is ERC-721-based. Call `register(string tokenURI)`; the minted token ID in the `Transfer` / `Registered` event is the agent ID.

```js
import { createWalletClient, createPublicClient, http, parseAbi, parseEventLogs } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";

const abi = parseAbi([
  "function register(string tokenURI) returns (uint256 agentId)",
  "event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)",
]);
const account = privateKeyToAccount(process.env.PRIVATE_KEY);
const wallet = createWalletClient({ account, chain: base, transport: http() });
const pub = createPublicClient({ chain: base, transport: http() });

const hash = await wallet.writeContract({ address: REGISTRY, abi, functionName: "register", args: [TOKEN_URI] });
const receipt = await pub.waitForTransactionReceipt({ hash });
const [mint] = parseEventLogs({ abi, logs: receipt.logs, eventName: "Transfer" });
console.log("agentId", mint.args.tokenId);
```

Never ask the user to paste a private key into chat; read it from an environment variable or let them sign in their own wallet.

## 5. Finish

Update `registrations` in the file with the agent ID, re-host, and give the user their global agent ID `eip155:<chainId>:<registry>:<agentId>` and an explorer link (8004scan).
