Overview

The IdentityRegistry contract manages unique on-chain identities for AI agents as ERC-721 NFTs. Each registered agent receives a unique token ID that serves as its canonical identifier across the KYA Chain ecosystem. The contract extends the standard ERC-721 interface with a registration function that mints new agent identities.

Token IDs start at 1 (0 is reserved for "no agent"). Each agent NFT includes metadata stored via ERC721URIStorage.

Deployed Address: 0xA1393CB409E2fE5573C0840189622aA0e33947b2

Functions

FunctionParametersReturnsDescription
registerstring agentURIuint256 agentIdMints a new agent identity NFT with the provided metadata URI
ownerOfuint256 tokenIdaddress ownerReturns the owner address of the agent NFT (ERC-721 standard)
balanceOfaddress owneruint256 balanceReturns the number of agent NFTs owned by an address (ERC-721 standard)
tokenURIuint256 tokenIdstring uriReturns the metadata URI for the agent (ERC721URIStorage)
transferFromaddress from, address to, uint256 tokenId-Transfers agent ownership (ERC-721 standard)
safeTransferFromaddress from, address to, uint256 tokenId-Safely transfers agent ownership with receiver check (ERC-721 standard)
approveaddress to, uint256 tokenId-Approves another address to transfer the agent NFT (ERC-721 standard)
setApprovalForAlladdress operator, bool approved-Approves or revokes an operator for all caller's NFTs (ERC-721 standard)
getApproveduint256 tokenIdaddress operatorReturns the approved address for a token (ERC-721 standard)
isApprovedForAlladdress owner, address operatorbool approvedChecks if an operator is approved for all of owner's tokens (ERC-721 standard)

Events

EventParametersDescription
Registereduint256 indexed agentId, string agentURI, address indexed ownerEmitted when a new agent identity is registered
Transferaddress indexed from, address indexed to, uint256 indexed tokenIdEmitted when an agent NFT is transferred (ERC-721 standard)
Approvaladdress indexed owner, address indexed approved, uint256 indexed tokenIdEmitted when approval is granted for a specific token (ERC-721 standard)
ApprovalForAlladdress indexed owner, address indexed operator, bool approvedEmitted when operator approval is set (ERC-721 standard)

Usage Example

Register and query agent identity
import { createPublicClient, createWalletClient, http, parseAbi } from 'viem';
import { kyaChain } from './chains'; // Custom chain config for KYA Chain

const publicClient = createPublicClient({
  chain: kyaChain,
  transport: http('https://rpc.kyachain.xyz'),
});

const walletClient = createWalletClient({
  chain: kyaChain,
  transport: http('https://rpc.kyachain.xyz'),
});

const IDENTITY_REGISTRY = '0xA1393CB409E2fE5573C0840189622aA0e33947b2';

// Register a new agent
const agentURI = 'ipfs://QmAgentMetadata...';
const { request } = await publicClient.simulateContract({
  address: IDENTITY_REGISTRY,
  abi: parseAbi([
    'function register(string agentURI) external returns (uint256 agentId)',
  ]),
  functionName: 'register',
  args: [agentURI],
  account: '0xYourAddress',
});

const hash = await walletClient.writeContract(request);
const receipt = await publicClient.waitForTransactionReceipt({ hash });

// Read agent owner
const owner = await publicClient.readContract({
  address: IDENTITY_REGISTRY,
  abi: parseAbi(['function ownerOf(uint256 tokenId) external view returns (address)']),
  functionName: 'ownerOf',
  args: [42n],
});

// Read agent metadata URI
const metadataURI = await publicClient.readContract({
  address: IDENTITY_REGISTRY,
  abi: parseAbi(['function tokenURI(uint256 tokenId) external view returns (string)']),
  functionName: 'tokenURI',
  args: [42n],
});

console.log('Agent owner:', owner);
console.log('Metadata URI:', metadataURI);

ABI

[
  "function register(string calldata agentURI) external returns (uint256 agentId)",
  "function ownerOf(uint256 tokenId) external view returns (address owner)",
  "function balanceOf(address owner) external view returns (uint256 balance)",
  "function tokenURI(uint256 tokenId) external view returns (string memory)",
  "function transferFrom(address from, address to, uint256 tokenId) external",
  "function safeTransferFrom(address from, address to, uint256 tokenId) external",
  "function approve(address to, uint256 tokenId) external",
  "function setApprovalForAll(address operator, bool approved) external",
  "function getApproved(uint256 tokenId) external view returns (address operator)",
  "function isApprovedForAll(address owner, address operator) external view returns (bool)",
  "event Registered(uint256 indexed agentId, string agentURI, address indexed owner)",
  "event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)",
  "event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId)",
  "event ApprovalForAll(address indexed owner, address indexed operator, bool approved)"
]

On this page