### Example: Get Client List Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Shows how to call getClients to obtain an array of client addresses. This list can then be used for further queries. ```solidity address[] memory allClients = await reputationRegistry.getClients(agentId) // Use this in readAllFeedback if you want to iterate over all clients ``` -------------------------------- ### Install Dependencies Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/README.md Run this command in your project directory to install all necessary npm packages. ```shell npm install ``` -------------------------------- ### ERC1967Proxy Initialization Example Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/uups-proxy.md Examples demonstrating how to create an ERC1967Proxy with encoded initialization data, either with no parameters or with specific parameters for initialization functions. ```solidity // Create proxy with initialization bytes memory initData = abi.encodeCall(IdentityRegistry.initialize, ()); address proxy = new ERC1967Proxy(implementationAddress, initData); // Or with parameters bytes memory initData = abi.encodeCall( ReputationRegistry.initialize, (identityRegistryAddress) ); address proxy = new ERC1967Proxy(implementationAddress, initData); ``` -------------------------------- ### Example: Get Response Counts Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Demonstrates how to call getResponseCount to retrieve total responses, responses for specific feedback, or responses from specific responders. ```solidity // Count all responses to all feedback for this agent uint64 totalResponses = await reputationRegistry.getResponseCount(agentId, address(0), 0, []) // Count responses to feedback 2 from a specific client uint64 responses = await reputationRegistry.getResponseCount(agentId, client, 2, []) // Count responses from specific responders address[] memory responders = [agent, auditor]; uint64 responses = await reputationRegistry.getResponseCount(agentId, address(0), 0, responders) ``` -------------------------------- ### UUPS Initialization Method Example Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/uups-proxy.md An example of an initialization method for a UUPS implementation contract. It uses the 'reinitializer' modifier for versioning and is restricted to the owner. ```solidity function initialize() public reinitializer(2) onlyOwner { __ERC721_init("AgentIdentity", "AGENT"); __ERC721URIStorage_init(); __EIP712_init("ERC8004IdentityRegistry", "1"); } ``` -------------------------------- ### Example: Initialize Validation Registry Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/validation-registry.md Example of how to initialize the Validation Registry contract using its address. ```javascript await validationRegistry.initialize("0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7") ``` -------------------------------- ### Example: Submit a Validation Request Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/validation-registry.md Example demonstrating how to create a deterministic request hash and submit a validation request. The request hash should be derived from agent ID, task description, and timestamp. ```javascript // Create a deterministic request hash bytes32 requestHash = keccak256(abi.encode( agentId, "performance_evaluation_2025_06_16", block.number )); await validationRegistry.validationRequest( auditorAddress, agentId, "ipfs://QmValidationDetails", requestHash ) ``` -------------------------------- ### Initialize and Register Agent with Metadata Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/types.md Example of initializing MetadataEntry array and registering an agent with IPFS hash and metadata. The metadataValue is encoded using abi.encodePacked. ```solidity MetadataEntry[] memory metadata = new MetadataEntry[](1); metadata[0] = MetadataEntry({ metadataKey: "paymentAddress", metadataValue: abi.encodePacked(address(0x123...)) }); uint256 agentId = await identityRegistry.register("ipfs://...", metadata); ``` -------------------------------- ### Generate Deterministic Request Hash (Simple) Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/validation-registry.md Example of generating a deterministic request hash using `keccak256` and `abi.encode` with basic parameters. ```solidity bytes32 requestHash = keccak256(abi.encode( agentId, validatorAddress, "evaluation_round_1" )); ``` -------------------------------- ### Localhost Deployment Script Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/UPGRADEABLE_IMPLEMENTATION.md Commands to start a local Hardhat node and run the full deployment script for the ERC-8004 contracts on localhost. ```bash # Start local node npx hardhat node # Run full deployment (in another terminal) npm run local ``` -------------------------------- ### Example: Giving Feedback with Percentage Value Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Illustrates using `giveFeedback` to record a whole number value, like a success rate percentage. Set `valueDecimals` to 0 for direct integer interpretation. ```javascript // Percentage score: 95% await reputationRegistry.giveFeedback( agentId, 95, 0, // valueDecimals: 0 (interpreted as "95") "success_rate", "a2a", "", "", bytes32(0) ) ``` -------------------------------- ### JavaScript/TypeScript Integration with Viem Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/deployment-addresses.md Integrate ERC-8004 contract addresses into your JavaScript or TypeScript project using the viem library. This example shows how to get contract instances for querying data. ```typescript import { getContract } from "viem"; const identityRegistryAddress = "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432"; const reputationRegistryAddress = "0x8004BAa17C55a88189AE136b182e5fdA19dE9b63"; const identityRegistry = getContract({ address: identityRegistryAddress, abi: IdentityRegistryABI, client: publicClient }); const reputationRegistry = getContract({ address: reputationRegistryAddress, abi: ReputationRegistryABI, client: publicClient }); // Query agents const agentOwner = await identityRegistry.read.ownerOf([agentId]); ``` -------------------------------- ### Example Agent ID Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/README.md An example of a fully qualified agent identifier, demonstrating the structure defined by namespace, chain ID, identity registry, and token ID. ```plaintext eip155:1:0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7:5 ``` -------------------------------- ### Get Clients Function Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Retrieves a list of all client addresses associated with a given agent. ```solidity function getClients(uint256 agentId) external view returns (address[] memory) ``` -------------------------------- ### Deploy ReputationRegistry with Hardhat Ignition Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/configuration.md Example deployment of the ReputationRegistry using Hardhat Ignition, encoding the identityRegistry_ address for initialization. ```typescript const IdentityRegistryAddress = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7"; const ReputationRegistryModule = buildModule("ReputationRegistryModule", (m) => { const implementation = m.contract("ReputationRegistryUpgradeable"); // Encode initialize(address identityRegistry_) const initData = encodeAbiParameters( [{ type: "address" }], [IdentityRegistryAddress] ); const proxy = m.contract("ERC1967Proxy", [implementation, initData]); const reputationRegistry = m.contractAt("ReputationRegistryUpgradeable", proxy); return { reputationRegistry }; }); export default ReputationRegistryModule; ``` -------------------------------- ### Deploy IdentityRegistry with Hardhat Ignition Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/configuration.md Example deployment of the IdentityRegistry using Hardhat Ignition, setting up the implementation and proxy contracts. ```typescript import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; const IdentityRegistryModule = buildModule("IdentityRegistryModule", (m) => { const implementation = m.contract("IdentityRegistryUpgradeable"); const proxy = m.contract("ERC1967Proxy", [implementation, "0x8129fc1c"]); // Init selector // Get reference through proxy const identityRegistry = m.contractAt("IdentityRegistryUpgradeable", proxy); return { identityRegistry }; }); export default IdentityRegistryModule; ``` -------------------------------- ### Find Vanity Salts in Parallel Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/VANITY_DEPLOYMENT_GUIDE.md Searches for CREATE2 salts that produce vanity addresses using parallel workers for speed. This is only needed if the initial setup is from scratch, MinimalUUPS bytecode changes, or proxy bytecode changes. ```bash npx hardhat run scripts/find-vanity-salts-parallel.ts --network ``` -------------------------------- ### Example: Giving Feedback with Decimal Value Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Demonstrates how to use the `giveFeedback` function to record a score with decimal places, such as a 4.5 out of 5 rating. Ensure `valueDecimals` correctly reflects the precision of `value`. ```javascript // Score of 4.5 / 5 await reputationRegistry.giveFeedback( agentId, 450, // value: 4.50 2, // valueDecimals: 2 decimal places (4.50) "quality", // tag1 "mcp", // tag2 "https://mcp.example.com", "https://feedback.example.com/f1", keccak256(abi.encode({...})) ) ``` -------------------------------- ### Deploy ValidationRegistry with Hardhat Ignition Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/configuration.md Example deployment of the ValidationRegistry using Hardhat Ignition, encoding the identityRegistry_ address for initialization. ```typescript const IdentityRegistryAddress = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7"; const ValidationRegistryModule = buildModule("ValidationRegistryModule", (m) => { const implementation = m.contract("ValidationRegistryUpgradeable"); // Encode initialize(address identityRegistry_) const initData = encodeAbiParameters( [{ type: "address" }], [IdentityRegistryAddress] ); const proxy = m.contract("ERC1967Proxy", [implementation, initData]); const validationRegistry = m.contractAt("ValidationRegistryUpgradeable", proxy); return { validationRegistry }; }); export default ValidationRegistryModule; ``` -------------------------------- ### UUPSUpgradeable Implementation Contract Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/uups-proxy.md An example of an implementation contract inheriting from UUPSUpgradeable. It must implement the _authorizeUpgrade function, which is restricted to the owner. ```solidity contract IdentityRegistryUpgradeable is ..., UUPSUpgradeable { function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} } ``` -------------------------------- ### Generate Deterministic Request Hash (Complex) Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/validation-registry.md Example of generating a deterministic request hash including task-specific details like ID, description, and expected output hash. ```solidity bytes32 requestHash = keccak256(abi.encode( agentId, taskId, taskDescription, expectedOutputHash )); ``` -------------------------------- ### Get Summary Function Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Retrieves a summary of feedback for a given agent, optionally filtered by client addresses and tags. Requires agentId and clientAddresses to be provided. ```solidity function getSummary(uint256 agentId, address[] calldata clientAddresses, string tag1, string tag2) external view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals) ``` -------------------------------- ### Get Agent Validation Summary Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md View function to get aggregated validation statistics for an agent. Optional filters for validator addresses and tags can be applied. ```solidity function getSummary(uint256 agentId, address[] calldata validatorAddresses, string tag) external view returns (uint64 count, uint8 averageResponse) ``` -------------------------------- ### Run Tests Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/README.md Execute the project's test suite using npm. ```shell npm test ``` -------------------------------- ### Testnet/Mainnet Deployment Steps Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/UPGRADEABLE_IMPLEMENTATION.md Sequence of commands for deploying ERC-8004 contracts on testnets or mainnet, including deploying the CREATE2 factory, deploying contracts, generating and broadcasting upgrades, and verification. ```bash # 1. Deploy CREATE2 factory (if needed) npx hardhat run scripts/deploy-create2-factory.ts --network # 2. Deploy all contracts npx hardhat run scripts/deploy-vanity.ts --network # 3. Generate pre-signed upgrades (requires OWNER_PRIVATE_KEY in .env) npx hardhat run scripts/generate-triple-presigned-upgrade.ts --network # 4. Broadcast upgrades npx hardhat run scripts/upgrade-vanity-presigned.ts --network # 5. Verify npx hardhat run scripts/verify-vanity.ts --network ``` -------------------------------- ### Reputation Registry - Get Identity Registry Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Retrieves the address of the identity registry. ```APIDOC ## Reputation Registry ### Description Provides functions to interact with the Reputation Registry, including retrieving the identity registry address. ### Function - `getIdentityRegistry() external view returns (address identityRegistry)`: Returns the address of the identity registry. ### Initialization The `identityRegistry` address is set during deployment via `initialize(address identityRegistry_)`. ``` -------------------------------- ### initialize Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Initializes the Reputation Registry by setting the Identity Registry address. This is crucial for validating agents and preventing self-feedback. ```APIDOC ## initialize(address identityRegistry_) ### Description Initializes the Reputation Registry by setting the Identity Registry address. Used to validate agents and prevent self-feedback. ### Method `initialize(address identityRegistry_)` ### Parameters #### Path Parameters - **identityRegistry_** (address) - Required - The Identity Registry contract address (must not be zero) ### Request Example ```solidity await reputationRegistry.initialize("0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7") ``` ### Response #### Success Response (200) None ### Error Handling - "bad identity" if identityRegistry_ is address(0) ``` -------------------------------- ### Localhost Deployment Script Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/VANITY_DEPLOYMENT_GUIDE.md Runs the full deployment process for localhost testing, including deploying the CREATE2 factory, and performing deployment, upgrade, and verification. ```bash npm run local ``` -------------------------------- ### Get Agent Validations Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md View function to retrieve all request hashes associated with a specific agent. ```solidity function getAgentValidations(uint256 agentId) external view returns (bytes32[] memory requestHashes) ``` -------------------------------- ### Get Identity Registry Address Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/validation-registry.md Retrieves the address of the Identity Registry contract used for authorization checks. ```solidity function getIdentityRegistry() external view returns (address) ``` -------------------------------- ### ReputationRegistry Initialization Function Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/configuration.md Initializes the Reputation Registry and links it to an Identity Registry instance. The identityRegistry_ parameter must not be address(0) and should point to the IdentityRegistry proxy address if using a proxy pattern. ```solidity function initialize(address identityRegistry_) public reinitializer(2) onlyOwner ``` -------------------------------- ### Get Validator Requests Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md View function to retrieve all request hashes processed by a specific validator address. ```solidity function getValidatorRequests(address validatorAddress) external view returns (bytes32[] memory requestHashes) ``` -------------------------------- ### Deploy Vanity Contracts Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/VANITY_DEPLOYMENT_GUIDE.md Deploys MinimalUUPS placeholder, vanity proxies, and real implementation contracts for ERC-8004. ```bash npx hardhat run scripts/deploy-vanity.ts --network ``` -------------------------------- ### Get Validation Status Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md View function to retrieve the status of a specific validation request using its hash. ```solidity function getValidationStatus(bytes32 requestHash) external view returns (address validatorAddress, uint256 agentId, uint8 response, bytes32 responseHash, string tag, uint256 lastUpdate) ``` -------------------------------- ### Store Address as Bytes Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/types.md Demonstrates how to encode an address into bytes using abi.encodePacked(). ```solidity // Store an address as bytes bytes memory addrBytes = abi.encodePacked(someAddress); ``` -------------------------------- ### Get Identity Registry Function Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Retrieves the address of the identityRegistry set during the Validation Registry's initialization. ```solidity getIdentityRegistry() ``` -------------------------------- ### Run Tests for Upgradeable Contracts Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/UPGRADEABLE_IMPLEMENTATION.md Execute the test suite for both core and upgradeable-specific functionality using the npm script. ```bash npm run test ``` -------------------------------- ### Get Identity Registry Address Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Retrieve the address of the identity registry. This is set during the Reputation Registry's initialization. ```solidity function getIdentityRegistry() external view returns (address identityRegistry) ``` -------------------------------- ### Generate Pre-signed Upgrade Transactions Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/VANITY_DEPLOYMENT_GUIDE.md Creates three signed transactions for upgrading each proxy to its real implementation. Requires OWNER_PRIVATE_KEY to be set in .env. ```bash npx hardhat run scripts/generate-triple-presigned-upgrade.ts --network ``` -------------------------------- ### Initialize Reputation Registry Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Initializes the Reputation Registry with the Identity Registry address. This function can only be called once and must be executed by the owner. ```solidity function initialize(address identityRegistry_) public reinitializer(2) onlyOwner ``` ```javascript await reputationRegistry.initialize("0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7") ``` -------------------------------- ### Get Last Index Function Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Retrieves the last feedback index submitted by a specific client address for a given agent. ```solidity function getLastIndex(uint256 agentId, address clientAddress) external view returns (uint64) ``` -------------------------------- ### Broadcast Pre-signed Upgrades Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/VANITY_DEPLOYMENT_GUIDE.md Loads pre-signed upgrade transactions from a JSON file, funds the owner address if necessary, and broadcasts all upgrade transactions. ```bash npx hardhat run scripts/upgrade-vanity-presigned.ts --network ``` -------------------------------- ### Get Version of Upgradeable Contract Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/UPGRADEABLE_IMPLEMENTATION.md Retrieve the current version of the upgradeable contract. Increment this value when deploying a new implementation. ```solidity function getVersion() external pure returns (string memory) { return "1.1.0"; } ``` -------------------------------- ### Initialize ReputationRegistry with Valid Identity Registry Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/errors.md When initializing the ReputationRegistry, ensure the identityRegistry_ parameter is a valid address and not the zero address. ```solidity // Provide a valid Identity Registry address address validRegistry = 0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7; await reputationRegistry.initialize(validRegistry); ``` -------------------------------- ### Two-Step UUPS Proxy Upgrade Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/uups-proxy.md Perform a two-step upgrade, first deploying a placeholder implementation and then upgrading to the real implementation when ready. This is useful for vanity addresses. ```solidity // Step 1: Deploy proxy with MinimalUUPS placeholder address minimalImpl = deployMinimalUUPS(); bytes memory initData = encodeInitialize(identityRegistry); address proxy = new ERC1967Proxy(minimalImpl, initData); // Step 2: When real implementation is ready, upgrade address realImpl = deployIdentityRegistry(); bytes memory upgradeData = encodeInitializeReinit(identityRegistry); IUUPSUpgradeable(proxy).upgradeToAndCall(realImpl, upgradeData); ``` -------------------------------- ### Get ERC-8004 Contract Version Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/identity-registry.md Retrieves the current implementation version of the ERC-8004 contract. This function is pure and does not modify the contract state. ```solidity function getVersion() external pure returns (string memory) ``` -------------------------------- ### Listen for New Feedback Events Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/integration-guide.md Set up a listener for new feedback events from the Reputation Registry. Stores incoming feedback data into an off-chain database. ```typescript // Listen for new feedback const filter = reputationRegistry.filters.NewFeedback( null, // any agentId null // any clientAddress ); reputationRegistry.on(filter, (agentId, clientAddr, index, value, decimals, tag1) => { // Store in database database.saveFeedback({ agentId: Number(agentId), client: clientAddr, feedbackIndex: Number(index), value: Number(value), decimals: Number(decimals), tag: tag1, timestamp: Date.now() }); }); ``` -------------------------------- ### Interpret Feedback Values Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/integration-guide.md Feedback values are interpreted as `value / (10^valueDecimals)`. This example shows how to calculate the actual rating from provided values and decimals. ```javascript // For a 4.5 / 5.0 star rating const value = 450; const decimals = 2; const actualRating = value / (10 ** decimals); // 4.5 // For a 95% success rate const value = 95; const decimals = 0; const actualRate = value / (10 ** decimals); // 95 (percent) ``` -------------------------------- ### Deploy CREATE2 Factory Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/VANITY_DEPLOYMENT_GUIDE.md Deploys the SAFE Singleton Factory using a pre-signed transaction. This factory consistently deploys to the same address on any chain. ```bash npx hardhat run scripts/deploy-create2-factory.ts --network ``` -------------------------------- ### Register Agent with URI Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/identity-registry.md Registers a new agent with a specified URI. The caller becomes the agent owner, and their address is automatically set as the agentWallet. The URI should point to a compatible JSON registration file. ```solidity function register(string memory agentURI) external returns (uint256 agentId) ``` ```javascript uint256 agentId = await identityRegistry.register("ipfs://QmXxxx...") uint256 agentId2 = await identityRegistry.register("https://example.com/agent.json") ``` -------------------------------- ### Get Response Count Function Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Retrieves the count of responses for a specific feedback entry, optionally filtered by responders. AgentId is the only mandatory parameter. ```solidity function getResponseCount(uint256 agentId, address clientAddress, uint64 feedbackIndex, address[] responders) external view returns (uint64 count) ``` -------------------------------- ### Provide Client Addresses for getSummary Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/errors.md When calling `getSummary`, the `clientAddresses` array must not be empty. This snippet demonstrates providing a list of client addresses or fetching all available clients first. ```solidity // Provide at least one client address to aggregate feedback from address[] memory clients = [client1, client2, client3]; (count, summaryValue, summaryDecimals) = await reputationRegistry.getSummary(agentId, clients, "quality", ""); // Or fetch all clients first, then aggregate address[] memory allClients = await reputationRegistry.getClients(agentId); (count, summaryValue, summaryDecimals) = await reputationRegistry.getSummary(agentId, allClients, "", ""); ``` -------------------------------- ### Get and Unset Agent Wallet Functions Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/ERC8004SPEC.md Provides functions to retrieve the current agent wallet address and to clear it, resetting it to the zero address. ```solidity function getAgentWallet(uint256 agentId) external view returns (address) function unsetAgentWallet(uint256 agentId) external ``` -------------------------------- ### Direct UUPS Proxy Upgrade Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/uups-proxy.md Execute an upgrade directly by calling `upgradeToAndCall` on the proxy. This atomically switches to the new implementation and runs initialization code. ```solidity // Called on the proxy by the owner proxy.upgradeToAndCall(newImplementationAddress, reinitializeData); ``` -------------------------------- ### Get Agent Reputation Summary Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/README.md Retrieve the aggregated reputation summary for an agent from the ReputationRegistry. This includes the count of feedback, average score, and decimal precision. ```solidity (uint64 count, int128 avg, uint8 decimals) = await reputationRegistry.getSummary(agentId, clients, "quality", ""); int256 score = int256(avg) / (10 ** uint256(decimals)); ``` -------------------------------- ### Run Tests with Hardhat Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/README.md Alternatively, run tests using the Hardhat development environment. ```shell npx hardhat test ``` -------------------------------- ### Register Agent with URI and Metadata Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/configuration.md Registers an agent with a URI and initial metadata entries. The 'agentWallet' key is reserved and cannot be set here. ```solidity MetadataEntry[] memory metadata = new MetadataEntry[](2); metadata[0] = MetadataEntry({ metadataKey: "key1", metadataValue: valueBytes1 }); metadata[1] = MetadataEntry({ metadataKey: "key2", metadataValue: valueBytes2 }); uint256 agentId = await identityRegistry.register("ipfs://...", metadata) ``` -------------------------------- ### Interact with Deployed Upgradeable Contract Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/UPGRADEABLE_IMPLEMENTATION.md Use the proxy address to get a contract instance and interact with it. Always use proxy addresses, not implementation addresses. ```typescript import hre from "hardhat"; // Get contract instance through proxy const identityRegistry = await hre.viem.getContractAt( "IdentityRegistryUpgradeable", "0x8004A818BFB912233c491871b3d84c89A494BD9e" // Use proxy address ); // Use normally const txHash = await identityRegistry.write.register(["ipfs://agent"]); ``` -------------------------------- ### Use Correct Methods for IdentityRegistry Metadata Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/errors.md Avoid using `setMetadata()` or `register()` with the reserved key 'agentWallet'. Use `setAgentWallet()` for wallet management and other keys for general metadata. ```Solidity // Use setAgentWallet() instead for the reserved key await identityRegistry.setAgentWallet(agentId, newWallet, deadline, signature); ``` ```Solidity // For other metadata, use any key name except "agentWallet" await identityRegistry.setMetadata(agentId, "customWallet", walletBytes); ``` -------------------------------- ### Example: Revoking Feedback Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Shows how to revoke a specific piece of feedback using the `revokeFeedback` function. Provide the agent ID and the 1-indexed feedback index to be revoked. ```javascript // Revoke the second feedback from this caller for this agent await reputationRegistry.revokeFeedback(agentId, 2) ``` -------------------------------- ### register(string memory agentURI, MetadataEntry[] memory metadata) Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/identity-registry.md Registers a new agent with both an agent URI and an array of initial metadata key-value pairs. The `agentWallet` is automatically assigned to the caller's address and cannot be set via this method. ```APIDOC ## register(string memory agentURI, MetadataEntry[] memory metadata) ### Description Registers a new agent with a URI and an array of initial metadata key-value pairs. The `agentWallet` cannot be set via this method; it is automatically set to the caller's address. ### Method `external returns (uint256 agentId)` ### Parameters #### Path Parameters - **agentURI** (string) - Required - URI pointing to agent registration file - **metadata** (MetadataEntry[]) - Required - Array of metadata key-value pairs to set at registration ### Throws - `"reserved key"` if any metadata entry uses the key `"agentWallet"` ### Return Value `uint256 agentId` — The newly assigned agent ID ### Example ```solidity MetadataEntry[] memory metadata = new MetadataEntry[](2); metadata[0] = MetadataEntry({ metadataKey: "tokenStandard", metadataValue: abi.encodePacked("ERC20") }); metadata[1] = MetadataEntry({ metadataKey: "paymentAddress", metadataValue: abi.encodePacked(address(0x123...)) }); uint256 agentId = await identityRegistry.register("ipfs://QmXxxx...", metadata) ``` ``` -------------------------------- ### Get Agent Wallet Address Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/identity-registry.md Retrieves the current agent wallet address for a given agent ID. Returns the zero address if the wallet has not been set or has been unset. ```solidity function getAgentWallet(uint256 agentId) external view returns (address) ``` ```javascript address walletAddr = await identityRegistry.getAgentWallet(0) ``` -------------------------------- ### Store String as Bytes Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/types.md Shows how to encode a string literal into bytes using abi.encodePacked(). ```solidity // Store a string as bytes (implicit) bytes memory strBytes = abi.encodePacked("some string"); ``` -------------------------------- ### Get Last Feedback Index Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/reputation-registry.md Retrieves the index of the most recent feedback entry from a specific client for a given agent. Useful for determining the valid range of feedback indices. ```solidity function getLastIndex(uint256 agentId, address clientAddress) external view returns (uint64) ``` ```javascript uint64 lastIdx = await reputationRegistry.getLastIndex(agentId, client) // Feedback indices for this client are 1..lastIdx ``` -------------------------------- ### Retrieve Agent Metadata Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/identity-registry.md Call this function to get on-chain metadata for a specific agent using its ID and a metadata key. Returns empty bytes if the key is not found. ```solidity function getMetadata(uint256 agentId, string memory metadataKey) external view returns (bytes memory) ``` ```javascript bytes memory value = await identityRegistry.getMetadata(0, "customKey") ``` -------------------------------- ### Verify Vanity Deployment Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/VANITY_DEPLOYMENT_GUIDE.md Performs comprehensive verification of the vanity deployment, checking proxy addresses, contract versions, ownership, implementation addresses, and cross-registry references. ```bash npx hardhat run scripts/verify-vanity.ts --network ``` -------------------------------- ### Event Emission in UUPS Proxy Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/uups-proxy.md Events are emitted by the implementation contract, not the proxy itself. The example shows an event definition and a call to a function on the proxy that triggers an event in the implementation's context. ```solidity // Event emitted by implementation event Registered(uint256 indexed agentId, string agentURI, address indexed owner); // Called on proxy, event emitted in context of implementation await identityRegistry.register("ipfs://..."); ``` -------------------------------- ### register() Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/identity-registry.md Registers a new agent without an initial URI. The caller automatically becomes the owner and the `agentWallet` is set to the caller's address. The URI can be set later using `setAgentURI()`. ```APIDOC ## register() ### Description Registers a new agent without setting a URI. The URI can be set later via `setAgentURI()`. The caller becomes the agent owner and the `agentWallet` is automatically set to the caller's address. ### Method `external returns (uint256 agentId)` ### Parameters None ### Return Value `uint256 agentId` — The newly assigned agent ID (auto-incremented from 0) ### Example ```solidity uint256 agentId = await identityRegistry.register() // agentId is 0 for the first agent, 1 for the second, etc. ``` ``` -------------------------------- ### Register Agent with URI and Metadata Source: https://github.com/erc-8004/erc-8004-contracts/blob/master/_autodocs/api-reference/identity-registry.md Registers a new agent with a URI and initial metadata. The `agentWallet` is automatically set to the caller's address and cannot be provided in the metadata. This function allows setting custom key-value metadata during registration. ```solidity function register(string memory agentURI, MetadataEntry[] memory metadata) external returns (uint256 agentId) ``` ```solidity MetadataEntry[] memory metadata = new MetadataEntry[](2); metadata[0] = MetadataEntry({ metadataKey: "tokenStandard", metadataValue: abi.encodePacked("ERC20") }); metadata[1] = MetadataEntry({ metadataKey: "paymentAddress", metadataValue: abi.encodePacked(address(0x123...)) }); uint256 agentId = await identityRegistry.register("ipfs://QmXxxx...", metadata) ```