My Phantom Drop project on Esmeralda never needed a custom template. It runs on native stealth features, so the only permission check I ever hit was signing a withdraw from my own account. Now I want to write my first real template, and before writing code I wanted to know exactly who can call what. So I sat down with the Authorization and Access guide, the Templates overview and the tari_template_lib source (0.36.0 on docs.rs). Most of the ways to hurt yourself as a template author live here. These are my notes.
Two ways into a template
An Ootle template is Rust compiled to WASM. The first pub struct in the template module becomes the component, and a component is one on-chain instance of the template with its own state. You can create many components from one template.
Inside the impl block you write three kinds of things:
-
Methods take
&selfor&mut self. They run against one component instance and are reached with theCallMethodinstruction, or by another component calling in. To change state, a method must take&mut self. -
Functions have no
self. They belong to the template, not to any instance, and are reached withCallFunction. Constructors are just functions: any function that returnsSelfcreates a component when it runs. -
Private
fnitems are not exposed at all. Only your own code can call them.
The library source puts the permission difference in two comments. A method "is callable as per the access rules defined for the component". An associated function provides "shared functionality callable by anyone".
That second line was the first thing I wrote down. Component access rules are a list of method names, and a template function has no component, so nothing in that list protects it. If a public function does anything important, the only defence is the checks you write inside it.
The default is closed
When you create a component with the simple constructor (fn new() -> Self), the defaults are strict. The library comment says that "all component methods are only callable by the component owner", meaning the same signer that created the component must sign any transaction that calls a method.
In the Guessing Game tutorial, players can't call guess until you add .method("guess", rule![allow_all]) to the component's rules. Everything you don't list stays owner-only.
There are two starting points. ComponentAccessRules::new() denies every method by default, and ComponentAccessRules::allow_all() opens every method by default. Then .method(name, rule) sets one method and .default(rule) covers the rest. Every method named in the rules must exist on the component or the transaction fails, so a typo can't quietly leave the real method on the default.
I'll start from new() every time. With allow_all(), any method I add later is public unless I remember to close it.
What a rule can ask for
Besides allow_all and deny_all, the rule! macro can require proof of a badge token (resource or non_fungible), a signature from a key (public_key), or a specific immediate caller (caller_component, direct_caller_template). any_of, all_of and m_of_n combine them, so "admin badge, or two of three signers" is one rule.
The owner is a separate thing
Ownership is set apart from the method rules with .with_owner_rule(...). The default is OwnedBySigner, the signer who created the component. The owner can always call any method and can change the access rules later. Setting OwnerRule::None leaves the component with no owner, which makes its access rules permanent.
So if I keep myself as owner, users are trusting me not to change the rules later. With OwnerRule::None they can read them once and know they are fixed.
Caller rules are sharper than they look
I read this section three times. component(addr) and template(addr) describe where execution is right now, which on a method rule is the callee itself. caller_component(addr) and direct_caller_template(addr) ask "who called me?", and only the immediate caller counts. If A calls B and B calls C, C sees B and never A.
The guide spells out three traps:
-
direct_caller_templatetrusts the whole package. It matches any component of that template (including ones anyone can create through a public constructor) and any of its static functions, which anyone can call. It is only as strong as the least careful outgoing call in that template. -
Proxy methods hand out identity. A method that forwards a caller-chosen component and method lets anyone act as the proxy.
-
caller_componenttrusts the owner of that component, not its current code, because the owner can migrate it to a different template.OwnerRule::Nonecloses this.
Also, a method called straight from a transaction has no caller frame, so caller rules deny it. If users should call it directly, gate it with a badge or a key.
Caller identity is a virtual badge stamped into each new call frame and re-derived at every call. The flip side: when your component calls out, the callee holds your identity as a live badge for its whole frame. Calling code you don't control lends it your name for that call.
Proofs are arguments, so put them in the signature
A proof (evidence that you hold a badge) only authorises in the frame that holds it. A proof that a transaction leaves on its workspace is checked at the call boundary, against the method's access rule, and stops there. The method's own frame doesn't hold it, so it can't use it to withdraw a badge-guarded resource.
So a method that acts on a badge-guarded resource takes the badge as a Proof argument and wraps the action in auth.authorize_with(...). The transaction creates the proof with the account's create_proof_for_resource and passes it in. The built-in account follows the same rule, with _with_auth variants of withdraw, deposit and create_proof_*. Phantom Drop only called plain withdraw on my own account, so I never hit this. A template holding badge-gated tokens will.
Resource rules, and why LOCKED is the important word
Resources have their own rules: who can mint, burn, recall, freeze, withdraw, deposit, update metadata and update NFT data. Each builder method takes two arguments: the rule that applies now, and an update rule saying who can change it later. There are three update rules:
-
LOCKED: nobody can change it, not even the resource owner. -
OWNER: only the resource owner can. -
An access rule: whoever satisfies it can, with no implicit override for the owner.
The guide's example: if recall is deny_all but the updater is OWNER, the issuer can switch recall back on after people hold the token. Same for freeze and mint. Only LOCKED is a promise holders can verify by reading the resource once.
The defaults from ResourceAccessRules::new() are safe: mint, burn, recall and freeze deny-all and locked; withdraw and deposit allow-all and locked; metadata and NFT data updates deny-all with the owner as updater. Any power you want to keep for later needs an updater on purpose.
You can also put a caller rule on a resource. withdrawable(rule!(caller_component(treasury)), LOCKED) is checked on every withdrawal, in every vault, in every component. A gate on one payout method only covers that one component.
Hooks: powerful, and a single point of failure
For live checks (a blocklist, a per-holder cap, a pause flag) a resource can delegate to an authorization hook, a method the engine calls on nearly every action. It denies by panicking and runs sandboxed: it can update its own state but can't touch other vaults or resources. On stealth resources every stealth transfer runs it as a Withdraw.
The guide is blunt about the risk. A hook that panics or denies everything takes the whole resource offline and strands every balance. The hook updater is locked by default, so without .with_authorization_hook_updater(...) a broken hook can't be fixed. An updater has a cost too: whoever holds it can retire a hook that holders relied on.
My checklist before I write the first line
-
Start from
ComponentAccessRules::new()and open methods one at a time. -
Treat every
pub fnwithoutselfas public, because it is. -
Decide whether I stay owner. If users must trust the rules,
OwnerRule::None. -
Avoid
direct_caller_templateunless I have read every outgoing call in that template. -
Take badges as
Proofarguments in the method signature. -
Mark
LOCKEDon any resource power I promise never to use. -
Budget for a broken hook, or don't use one.
Sources: Tari Ootle docs, Authorization and Access (ootle.tari.com/guides/authorization-and-access/), Templates Overview (ootle.tari.com/guides/template-overview/), Building a Guessing Game (ootle.tari.com/guides/build-a-guessing-game/), and the tari_template_lib 0.36.0 crate docs on docs.rs. Read on 2026-10-30 UTC.
Official docs: Tari Ootle guide: Authorization and Access