Getting Started
This guide walks you through registering your first AI agent on KYA Chain. You'll learn how to configure a client, register an agent identity NFT, stake LABS tokens for trust, and generate an API key for off-chain verification.
Prerequisites
Before you begin, ensure you have:
- Node.js 18+ installed
- A wallet with LABS tokens -- You'll need LABS for gas fees and staking
- viem library -- Install with
npm install viem
Warning: This guide uses the KYA Chain mainnet. There is no testnet. For local development and testing, use Foundry's
anvilto run a local chain with contract deployments.
Step 1: Configure the KYA Chain Client
First, set up viem clients to interact with KYA Chain:
import { createPublicClient, createWalletClient, http, defineChain } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
const kyaChain = defineChain({
id: 8004,
name: 'KYA Chain',
nativeCurrency: { name: 'LABS', symbol: 'LABS', decimals: 18 },
rpcUrls: {
default: { http: ['https://rpc.kyachain.xyz'] },
},
});
const account = privateKeyToAccount('0xYOUR_PRIVATE_KEY');
const publicClient = createPublicClient({
chain: kyaChain,
transport: http(),
});
const walletClient = createWalletClient({
account,
chain: kyaChain,
transport: http(),
});Warning: Never commit your private key to source control. Use environment variables or a secure key management system.
Step 2: Register an AI Agent
Register your agent by calling the register function on the IdentityRegistry contract:
const IDENTITY_REGISTRY = '0xA1393CB409E2fE5573C0840189622aA0e33947b2';
const abi = [
{
type: 'function',
name: 'register',
inputs: [{ name: 'agentURI', type: 'string' }],
outputs: [{ name: 'agentId', type: 'uint256' }],
stateMutability: 'nonpayable',
},
{
type: 'event',
name: 'Registered',
inputs: [
{ name: 'agentId', type: 'uint256', indexed: true },
{ name: 'agentURI', type: 'string', indexed: false },
{ name: 'owner', type: 'address', indexed: true },
],
},
] as const;
// Register the agent
const hash = await walletClient.writeContract({
address: IDENTITY_REGISTRY,
abi,
functionName: 'register',
args: ['https://my-agent.com/metadata.json'],
});
// Wait for transaction confirmation
const receipt = await publicClient.waitForTransactionReceipt({ hash });
// Extract agentId from the Registered event
const log = receipt.logs.find(
(log) => log.address.toLowerCase() === IDENTITY_REGISTRY.toLowerCase()
);
const agentId = log ? BigInt(log.topics[1]) : 0n;
console.log(`Agent registered with ID: ${agentId}`);The agentURI should point to a JSON metadata file describing your agent. This follows the ERC-721 metadata standard.
Step 3: Verify Your Agent Exists
Confirm your agent was registered successfully:
const erc721Abi = [
{
type: 'function',
name: 'ownerOf',
inputs: [{ name: 'tokenId', type: 'uint256' }],
outputs: [{ name: 'owner', type: 'address' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'tokenURI',
inputs: [{ name: 'tokenId', type: 'uint256' }],
outputs: [{ name: 'uri', type: 'string' }],
stateMutability: 'view',
},
] as const;
const owner = await publicClient.readContract({
address: IDENTITY_REGISTRY,
abi: erc721Abi,
functionName: 'ownerOf',
args: [agentId],
});
const uri = await publicClient.readContract({
address: IDENTITY_REGISTRY,
abi: erc721Abi,
functionName: 'tokenURI',
args: [agentId],
});
console.log(`Owner: ${owner}`);
console.log(`Metadata URI: ${uri}`);Step 4: Stake LABS for Trust
Staking LABS tokens establishes your agent's trust tier. Higher tiers unlock additional platform capabilities and signal stronger economic commitment.
Trust Tiers
| Tier | Name | LABS Required | Use Case |
|---|---|---|---|
| 1 | Bronze | 1,000 | Basic verification, testing |
| 2 | Silver | 10,000 | Production agents, standard trust |
| 3 | Gold | 100,000 | High-value transactions, enhanced trust |
| 4 | Diamond | 500,000 | Enterprise agents, maximum trust |
Staking Process
First, wrap your native LABS tokens into WLABS (ERC-20):
const WLABS = '0xEd863CAd86f69D8821f678784c5a47d21626BBF7';
const wlabsAbi = [
{
type: 'function',
name: 'deposit',
inputs: [],
outputs: [],
stateMutability: 'payable',
},
{
type: 'function',
name: 'approve',
inputs: [
{ name: 'spender', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
outputs: [{ name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
},
] as const;
// Wrap 10,000 LABS (for Silver tier)
const depositHash = await walletClient.writeContract({
address: WLABS,
abi: wlabsAbi,
functionName: 'deposit',
value: 10_000n * 10n ** 18n, // 10,000 LABS in wei
});
await publicClient.waitForTransactionReceipt({ hash: depositHash });Next, approve the TrustVault to spend your WLABS:
const TRUST_VAULT = '0xD4bAE271bCCb8bA7BF13B0B4743d62E61CCF9E0e';
const approveHash = await walletClient.writeContract({
address: WLABS,
abi: wlabsAbi,
functionName: 'approve',
args: [TRUST_VAULT, 10_000n * 10n ** 18n],
});
await publicClient.waitForTransactionReceipt({ hash: approveHash });Finally, stake your WLABS:
const trustVaultAbi = [
{
type: 'function',
name: 'stake',
inputs: [
{ name: 'agentId', type: 'uint256' },
{ name: 'amount', type: 'uint256' },
],
outputs: [],
stateMutability: 'nonpayable',
},
] as const;
const stakeHash = await walletClient.writeContract({
address: TRUST_VAULT,
abi: trustVaultAbi,
functionName: 'stake',
args: [agentId, 10_000n * 10n ** 18n],
});
await publicClient.waitForTransactionReceipt({ hash: stakeHash });
console.log('Successfully staked 10,000 LABS for Silver tier');Step 5: Generate an API Key
The Verification API allows off-chain verification of agent identities using EIP-712 signatures. To use the API, you need to generate an API key.
API key generation requires signing an EIP-712 message with your agent's owner wallet. The signature proves ownership without exposing your private key.
For detailed instructions on EIP-712 signature generation and API key creation, see:
- EIP-712 Signatures Guide -- Learn how to create typed signatures
- Authentication -- API key generation and usage
Next Steps
You've successfully registered an AI agent and established trust on KYA Chain. Here's what to explore next:
- Smart Contracts -- Deep dive into contract interfaces and functions
- Verification API -- Learn how to verify agent identities off-chain
- Network Configuration -- Reference for chain parameters and contract addresses
- Tier Upgrades Guide -- How to increase your agent's trust tier