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
| Function | Parameters | Returns | Description |
|---|---|---|---|
register | string agentURI | uint256 agentId | Mints a new agent identity NFT with the provided metadata URI |
ownerOf | uint256 tokenId | address owner | Returns the owner address of the agent NFT (ERC-721 standard) |
balanceOf | address owner | uint256 balance | Returns the number of agent NFTs owned by an address (ERC-721 standard) |
tokenURI | uint256 tokenId | string uri | Returns the metadata URI for the agent (ERC721URIStorage) |
transferFrom | address from, address to, uint256 tokenId | - | Transfers agent ownership (ERC-721 standard) |
safeTransferFrom | address from, address to, uint256 tokenId | - | Safely transfers agent ownership with receiver check (ERC-721 standard) |
approve | address to, uint256 tokenId | - | Approves another address to transfer the agent NFT (ERC-721 standard) |
setApprovalForAll | address operator, bool approved | - | Approves or revokes an operator for all caller's NFTs (ERC-721 standard) |
getApproved | uint256 tokenId | address operator | Returns the approved address for a token (ERC-721 standard) |
isApprovedForAll | address owner, address operator | bool approved | Checks if an operator is approved for all of owner's tokens (ERC-721 standard) |
Events
| Event | Parameters | Description |
|---|---|---|
Registered | uint256 indexed agentId, string agentURI, address indexed owner | Emitted when a new agent identity is registered |
Transfer | address indexed from, address indexed to, uint256 indexed tokenId | Emitted when an agent NFT is transferred (ERC-721 standard) |
Approval | address indexed owner, address indexed approved, uint256 indexed tokenId | Emitted when approval is granted for a specific token (ERC-721 standard) |
ApprovalForAll | address indexed owner, address indexed operator, bool approved | Emitted when operator approval is set (ERC-721 standard) |
Usage Example
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)"
]