IPcl.policyTemplate

policyTemplate(
  string calldata templateId
) external view returns (PolicyTemplate memory)

Returns the descriptor for a registered PCL policy template. The returned PolicyTemplate struct carries only three fields — templateId, name, and description — and is metadata-only: it does not embed a machine-readable parameter schema. To learn a template's parameter shape, consult the template-specific struct in IPcl.sol (for example DenylistPolicy, EasPolicy). If the requested templateId is not currently registered on this network, the call reverts with PolicyTemplateNotFound.

Parameters

Name Type Required Description
templateId string The machine-readable template ID, e.g. "DENYLIST_POLICY" or "EAS_POLICY". Case-sensitive and must match a registered template exactly.

Returns

Type: PolicyTemplate

A struct with three fields: string templateId (echoes the input on success), string name (human-readable label), and string description (short prose description of the template's evaluation rule).

Errors

Code Name Description
PolicyTemplateNotFound PolicyTemplateNotFound Reverts when no template is registered under templateId. Encoded as PolicyTemplateNotFound(string templateId) so clients can display which id failed the lookup.

Examples

Reading a template descriptor with viem

The returned tuple has exactly three fields. Callers that previously read a paramSchema byte string must remove that access — the field no longer exists.

import { createPublicClient, http } from "viem";

const PCL = "0x1000000000000000000000000000000000000005" as const;
const pclAbi = [{
  type: "function", name: "policyTemplate", stateMutability: "view",
  inputs: [{ name: "templateId", type: "string" }],
  outputs: [{
    type: "tuple", components: [
      { name: "templateId",  type: "string" },
      { name: "name",        type: "string" },
      { name: "description", type: "string" },
    ],
  }],
}] as const;

const publicClient = createPublicClient({ transport: http("https://rpc-testnet.maroo.io") });

const tpl = await publicClient.readContract({
  address: PCL,
  abi: pclAbi,
  functionName: "policyTemplate",
  args: ["EAS_POLICY"],
});
console.log(tpl.templateId, tpl.name, tpl.description);

Handling a missing template

Use PolicyTemplateNotFound as a pre-flight check before building a PolicySet for that template — if the id is not registered on this network, changeContractPolicies will fail the same way.

import { createPublicClient, http, decodeErrorResult } from "viem";

const PCL = "0x1000000000000000000000000000000000000005" as const;
const pclAbi = [
  { type: "function", name: "policyTemplate", stateMutability: "view",
    inputs: [{ name: "templateId", type: "string" }],
    outputs: [{
      type: "tuple", components: [
        { name: "templateId",  type: "string" },
        { name: "name",        type: "string" },
        { name: "description", type: "string" },
      ],
    }] },
  { type: "error", name: "PolicyTemplateNotFound",
    inputs: [{ name: "templateId", type: "string" }] },
] as const;

const publicClient = createPublicClient({ transport: http("https://rpc-testnet.maroo.io") });

try {
  await publicClient.readContract({
    address: PCL,
    abi: pclAbi,
    functionName: "policyTemplate",
    args: ["NOT_A_REAL_TEMPLATE"],
  });
} catch (err: any) {
  if (err?.data) {
    const decoded = decodeErrorResult({ abi: pclAbi, data: err.data });
    if (decoded.errorName === "PolicyTemplateNotFound") {
      console.warn("template not registered:", decoded.args[0]);
    }
  }
}
ESC
Type to search