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
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 fails too — with PolicyNotRegistered(templateId), or UnknownPolicyType(templateId) for an id that is not a policy type at all.
import { BaseError, ContractFunctionRevertedError, createPublicClient, http, decodeErrorResult } from "viem";
import { iPclAbi } from "@maroo-chain/contracts/abi/precompiles/pcl/IPcl";
const PCL = "0x1000000000000000000000000000000000000005" as const;
const publicClient = createPublicClient({ transport: http("https://rpc-testnet.maroo.io") });
try {
await publicClient.readContract({
address: PCL,
abi: iPclAbi,
functionName: "policyTemplate",
args: ["NOT_A_REAL_TEMPLATE"],
});
} catch (err) {
// viem keeps the revert data on the ContractFunctionRevertedError in the cause chain, not on err.
const revert = err instanceof BaseError ? err.walk((e) => e instanceof ContractFunctionRevertedError) : null;
if (revert instanceof ContractFunctionRevertedError && revert.raw) {
// iPclAbi lists every IPcl error, the IPrecompile ones it inherits included
const decoded = decodeErrorResult({ abi: iPclAbi, data: revert.raw });
if (decoded.errorName === "PolicyTemplateNotFound") {
console.warn("template not registered:", decoded.args[0]);
} else {
throw err; // a different revert: not the case this example handles
}
} else {
throw err; // not a revert (a network error, a wrong ABI): let it surface
}
}