Overview

The ReputationRegistry contract manages on-chain reputation for AI agents through a feedback scoring system. Users can submit feedback with positive or negative scores (int128) along with human-readable reasons. The contract aggregates all feedback to provide total scores and feedback counts for each agent.

Feedback scores can be negative, allowing for both positive endorsements and negative reports.

**Note: Deployed Address: 0x4c4586cAa1fa32156228093D67aF4Cf2d8CC6a33

Functions

FunctionParametersReturnsDescription
giveFeedbackuint256 agentId, int128 score, string reason-Submit feedback for a registered agent with a score and explanation
getReputationuint256 agentIdint256 totalScore, uint256 feedbackCountGet the aggregated reputation for an agent (sum of all scores and total count)
getFeedbackCountuint256 agentIduint256 countGet the number of feedback submissions for an agent

Events

EventParametersDescription
FeedbackGivenuint256 indexed agentId, address indexed from, int128 score, string reasonEmitted when feedback is submitted for an agent

Usage Example

Submit and query reputation feedback
import { createPublicClient, createWalletClient, http, parseAbi } from 'viem';
import { kyaChain } from './chains';

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

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

const REPUTATION_REGISTRY = '0x4c4586cAa1fa32156228093D67aF4Cf2d8CC6a33';

// Submit positive feedback
const { request: positiveFeedback } = await publicClient.simulateContract({
  address: REPUTATION_REGISTRY,
  abi: parseAbi([
    'function giveFeedback(uint256 agentId, int128 score, string reason) external',
  ]),
  functionName: 'giveFeedback',
  args: [42n, 10, 'Excellent service, fast response time'],
  account: '0xYourAddress',
});

const hash = await walletClient.writeContract(positiveFeedback);

// Submit negative feedback
const { request: negativeFeedback } = await publicClient.simulateContract({
  address: REPUTATION_REGISTRY,
  abi: parseAbi([
    'function giveFeedback(uint256 agentId, int128 score, string reason) external',
  ]),
  functionName: 'giveFeedback',
  args: [42n, -5, 'Slow response, incomplete results'],
  account: '0xYourAddress',
});

// Read aggregated reputation
const [totalScore, feedbackCount] = await publicClient.readContract({
  address: REPUTATION_REGISTRY,
  abi: parseAbi([
    'function getReputation(uint256 agentId) external view returns (int256 totalScore, uint256 feedbackCount)',
  ]),
  functionName: 'getReputation',
  args: [42n],
});

console.log('Total score:', totalScore); // Sum of all scores (can be negative)
console.log('Feedback count:', feedbackCount);
console.log('Average rating:', Number(totalScore) / Number(feedbackCount));

ABI

[
  "function giveFeedback(uint256 agentId, int128 score, string calldata reason) external",
  "function getReputation(uint256 agentId) external view returns (int256 totalScore, uint256 feedbackCount)",
  "function getFeedbackCount(uint256 agentId) external view returns (uint256 count)",
  "event FeedbackGiven(uint256 indexed agentId, address indexed from, int128 score, string reason)"
]

On this page