Skip to content

Overhaul ERC-8004 agent integration — detection, management, deadline fix #583

@realproject7

Description

@realproject7

Problem

The current agent registration UI has several gaps and one critical bug when compared to the actual ERC-8004 IdentityRegistryUpgradeable contract behavior.

Critical Bug

Wallet binding will revert on-chain. The UI sets deadline = Math.floor(Date.now() / 1000) + 3600 (1 hour) in AgentRegister.tsx line 112, but the contract enforces a maximum 5-minute deadline. Any setAgentWallet() call will fail.

Fix: Change deadline to Math.floor(Date.now() / 1000) + 300 (5 minutes).

Missing Features

1. Existing agent detection on page load

When a wallet connects on the /agents page, check:

  • agentIdByWallet(address) — is this wallet currently bound as an agent wallet?
  • balanceOf(address) — does this wallet own any AGENT NFTs? (ERC-721 standard)
  • If either returns positive, skip registration and show agent profile/management UI

This handles:

  • Wallets registered on PlotLink
  • Wallets registered from other apps using the same ERC-8004 registry
  • Creator wallets that own the NFT but have a separate agent wallet bound

2. Owner vs Agent Wallet distinction

The contract has two separate roles:

Role How assigned What agentIdByWallet() returns
Owner Holds the AGENT NFT (ERC-721 ownerOf) Nothing — not indexed by this function
Agent Wallet Set via setAgentWallet() or auto-set to caller on register() The agentId

Current code only checks agentIdByWallet(), which misses the case where:

  • A creator wallet owns the NFT (is the owner)
  • But has bound a different hot wallet as the agentWallet
  • The creator connects to PlotLink → Dashboard shows "not registered" (wrong)

Fix: Also check if the wallet owns AGENT NFTs. If it does, fetch the agentId from the token (enumerate via ERC-721 tokenOfOwnerByIndex or events), then show the management UI.

3. Agent management UI for existing agents

When an existing agent is detected, show a management panel instead of registration:

  • View: Agent ID, current URI metadata, current agent wallet (getAgentWallet(agentId))
  • Update URI: Call setAgentURI(agentId, newURI) — owner/approved only
  • Change agent wallet: Call setAgentWallet(agentId, newWallet, deadline, sig) with correct 5-min deadline
  • Unset agent wallet: Call unsetAgentWallet(agentId) — clears the binding entirely
  • Update metadata: Call setMetadata(agentId, key, value) for arbitrary metadata

4. Registration guard

Before showing the registration form, check if the connected wallet already has an agentId. If yes, redirect to management UI. Prevent duplicate registrations.

Contract ABI additions needed

Add these to lib/contracts/erc8004.ts:

// Already have: register, setAgentWallet, agentIdByWallet, agentURI

// Need to add:
function getAgentWallet(uint256 agentId) external view returns (address)
function unsetAgentWallet(uint256 agentId) external
function setAgentURI(uint256 agentId, string newURI) external
function setMetadata(uint256 agentId, string key, bytes value) external
function getMetadata(uint256 agentId, string key) external view returns (bytes)
function balanceOf(address owner) external view returns (uint256)  // ERC-721
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256)  // ERC-721 Enumerable, if supported
function ownerOf(uint256 tokenId) external view returns (address)  // ERC-721

// Events to add:
event URIUpdated(uint256 indexed agentId, string newURI, address indexed updatedBy)
event MetadataSet(uint256 indexed agentId, string indexed indexedMetadataKey, string metadataKey, bytes metadataValue)

Files to modify

  • src/components/AgentRegister.tsx — fix deadline (CRITICAL), add existing-agent detection, management UI
  • src/components/AgentDashboard.tsx — handle owner-vs-agentWallet distinction
  • lib/contracts/erc8004.ts — add missing ABI entries, add helper functions

Branch

task/582-erc8004-overhaul

Acceptance criteria

  • CRITICAL: Wallet binding deadline changed from 3600 to 300 seconds
  • On page load, detect if wallet is already registered (as agent wallet OR as NFT owner)
  • Existing agents see management UI, not registration form
  • Management UI: view agent info, update URI, change/unset agent wallet
  • Owner wallets that don't have agentWallet bound still show their agent in Dashboard
  • New ABI entries added for getAgentWallet, unsetAgentWallet, setAgentURI, setMetadata
  • Build passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions