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
Problem
The current agent registration UI has several gaps and one critical bug when compared to the actual ERC-8004
IdentityRegistryUpgradeablecontract behavior.Critical Bug
Wallet binding will revert on-chain. The UI sets
deadline = Math.floor(Date.now() / 1000) + 3600(1 hour) inAgentRegister.tsxline 112, but the contract enforces a maximum 5-minute deadline. AnysetAgentWallet()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
/agentspage, check:agentIdByWallet(address)— is this wallet currently bound as an agent wallet?balanceOf(address)— does this wallet own any AGENT NFTs? (ERC-721 standard)This handles:
2. Owner vs Agent Wallet distinction
The contract has two separate roles:
agentIdByWallet()returnsownerOf)setAgentWallet()or auto-set to caller onregister()Current code only checks
agentIdByWallet(), which misses the case where:Fix: Also check if the wallet owns AGENT NFTs. If it does, fetch the agentId from the token (enumerate via ERC-721
tokenOfOwnerByIndexor 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:
getAgentWallet(agentId))setAgentURI(agentId, newURI)— owner/approved onlysetAgentWallet(agentId, newWallet, deadline, sig)with correct 5-min deadlineunsetAgentWallet(agentId)— clears the binding entirelysetMetadata(agentId, key, value)for arbitrary metadata4. 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:Files to modify
src/components/AgentRegister.tsx— fix deadline (CRITICAL), add existing-agent detection, management UIsrc/components/AgentDashboard.tsx— handle owner-vs-agentWallet distinctionlib/contracts/erc8004.ts— add missing ABI entries, add helper functionsBranch
task/582-erc8004-overhaulAcceptance criteria