IAgent.getParams

getParams() external view returns (Params memory)

Agent 모듈이 이 체인에서 해석하는 표준 주소를 반환합니다. 반환값은 ERC-8004 identityRegistryreputationRegistry preinstall 주소입니다. dApp이 네트워크마다 주소를 하드코딩하지 않아도 되도록 시작 시점에 한 번 호출합니다. 이 프리컴파일은 공유 IPrecompile 오류 인터페이스를 상속하므로, 실패는 별도로 정의된 오류가 아니라 공유 타입 지정 오류로 반환됩니다.

파라미터

이 메서드는 파라미터가 없습니다.

반환값

타입: tuple

두 필드를 가진 Params 구조체를 반환합니다. identityRegistry는 ERC-8004 IdentityRegistry preinstall 주소이고, reputationRegistry는 ERC-8004 ReputationRegistry preinstall 주소입니다.

에러

코드 이름 설명
InvalidNumberOfArgs InvalidNumberOfArgs ABI 디코딩된 인자 개수가 메서드 시그니처와 일치하지 않을 때 revert됩니다. getParams는 인자를 받지 않으므로 여분의 ABI 인코딩 값이 있으면 이 오류가 발생합니다. InvalidNumberOfArgs(uint256 expected, uint256 got) 형태로 인코딩됩니다.
UnknownMethod UnknownMethod calldata가 이 프리컴파일에서 인식하는 메서드 selector와 일치하지 않을 때 revert됩니다. UnknownMethod(string methodName) 형태로 인코딩됩니다.
QueryFailed QueryFailed Agent 모듈의 내부 파라미터 조회가 실패할 때 revert됩니다. QueryFailed(string queryMethod, string reason) 형태로 인코딩됩니다. reason 문자열에는 실제 실패 메시지가 담기며, 공유 SDK 오류 레지스트리에 매핑되는 코드(예: SDKNotFound)에 해당하면 해당 코드로 정규화됩니다.

예제

시작 시점에 레지스트리 주소 해석

반환되는 주소는 체인 바이너리 업그레이드를 거쳐도 안정적으로 유지되므로, 프로세스 수명 동안 캐시해도 됩니다.

import { createPublicClient, http } from "viem";

const AGENT_PRECOMPILE = "0x100000000000000000000000000000000000000A" as const;
const agentAbi = [{
  type: "function", name: "getParams", stateMutability: "view",
  inputs: [],
  outputs: [{
    type: "tuple", components: [
      { name: "identityRegistry",   type: "address" },
      { name: "reputationRegistry", type: "address" },
    ],
  }],
}] as const;

const publicClient = createPublicClient({ transport: http("https://rpc-testnet.maroo.io") });
const { identityRegistry, reputationRegistry } = await publicClient.readContract({
  address: AGENT_PRECOMPILE,
  abi: agentAbi,
  functionName: "getParams",
});

console.log("IdentityRegistry:", identityRegistry);
console.log("ReputationRegistry:", reputationRegistry);

공유 IPrecompile 오류 인터페이스에서 타입 지정 오류 디코드

Agent 프리컴파일의 모든 실패는 IPrecompile 오류 집합을 공유하므로, ABI 하나로 모든 revert 형태를 처리할 수 있습니다.

import { decodeErrorResult } from "viem";

const iPrecompileAbi = [
  { type: "error", name: "InvalidNumberOfArgs",
    inputs: [{ name: "expected", type: "uint256" }, { name: "got", type: "uint256" }] },
  { type: "error", name: "UnknownMethod", inputs: [{ name: "methodName", type: "string" }] },
  { type: "error", name: "QueryFailed",
    inputs: [{ name: "queryMethod", type: "string" }, { name: "reason", type: "string" }] },
] as const;

try {
  await publicClient.readContract({ address: AGENT_PRECOMPILE, abi: agentAbi, functionName: "getParams" });
} catch (err: any) {
  if (err?.data) {
    const decoded = decodeErrorResult({ abi: iPrecompileAbi, data: err.data });
    console.error("getParams reverted:", decoded.errorName, decoded.args);
  } else {
    throw err;
  }
}
ESC
검색어를 입력하세요