Msg/CreatePolicyTemplate
CreatePolicyTemplate(ctx context.Context, in *MsgCreatePolicyTemplate) (*MsgCreatePolicyTemplateResponse, error) Creates and registers a new, reusable policy template on-chain. Policy templates contain a set of compliance rules that can be applied to smart contracts. This action can only be performed by the designated policy administrator.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
authority | string | ✓ | The bech32 address of the policy administrator account. Must match the policy_admin parameter of the pcl module. |
name | string | ✓ | A unique, human-readable name for the policy template (e.g., 'kyc-level-1-required'). |
description | string | - | A brief description of what the policy template enforces. |
rules | Rule[] | ✓ | An array of rule objects that define the compliance logic. Each rule is a string representing a predefined check (e.g., 'SENDER_HAS_KYC'). |
Returns
Type:
MsgCreatePolicyTemplateResponse Returns a response containing the unique ID of the newly created policy template.
Errors
| Code | Name | Description |
|---|---|---|
codes.PermissionDenied | Unauthorized | Occurs if the `authority` address does not match the module's policy administrator. |
codes.AlreadyExists | TemplateNameInUse | Occurs if a policy template with the given `name` already exists. |
Examples
Create a template using Go client
This example creates a simple policy template that requires the transaction sender to have a valid KYC attestation.
import (
"context"
pclv1 "maroo/api/maroo/pcl/v1"
"google.golang.org/grpc"
)
func createKycPolicy(conn *grpc.ClientConn, adminAddr string) (*pclv1.MsgCreatePolicyTemplateResponse, error) {
msgClient := pclv1.NewMsgClient(conn)
msg := &pclv1.MsgCreatePolicyTemplate{
Authority: adminAddr,
Name: "kyc-required-policy",
Description: "Requires sender to have completed KYC.",
Rules: []*pclv1.Rule{{Definition: "SENDER_HAS_KYC"}},
}
return msgClient.CreatePolicyTemplate(context.Background(), msg)
} Create a template using grpcurl
A `grpcurl` command to register the same KYC policy template from the command line.
grpcurl -d '{
"authority": "maroo1...",
"name": "kyc-required-policy",
"description": "Requires sender to have completed KYC.",
"rules": [
{ "definition": "SENDER_HAS_KYC" }
]
}' -plaintext [maroo-node-ip]:9090 maroo.pcl.v1.Msg.CreatePolicyTemplate