Give anyone a spending cap they cannot exceed. Funds go from your vault straight to the merchant, or the payment fails and nothing moves.
When Alice grants Bob a cap, this bar shows how much of it is still left to spend.
| Account | Balance | Receipts |
|---|
| Helper | Cap | Remaining | Status | Allowlist |
|---|
The Rust Ootle template in template/ is the on-chain version of the engine this page runs. Engine tests in Node and in tari_template_test_tooling cover the same rules.
| UI action | Template method | Who can call it |
|---|---|---|
| Open purse | CapPurse::new(alloc) | Signer becomes owner |
| Deposit | deposit(bucket) | Anyone, TARI only |
| Grant Bob | grant(helper, label, cap, period_epochs, expires_at_epoch, allowlist) | Owner |
| Change cap | set_cap(helper, new_cap) | Owner |
| Change allowed shops | set_allowlist(helper, allowlist) | Owner |
| Bob spends | spend(amount, merchant, memo) → receipt NFT | The helper (checked inside the method) |
| Revoke | revoke(helper) | Owner |
| Undo revoke | reactivate(helper) | Owner, only before expiry |
| Withdraw | withdraw(amount) → Bucket | Owner |
| Read balance | vault_balance() | Anyone |
| Read allowance | allowance_of(helper) → AllowanceView | Anyone |
| Find receipts | receipt_resource() → ResourceAddress | Anyone |
| Period refill | Consensus::current_epoch(), automatic on spend | — |
These are the calls the engine tests in template/tests/engine.rs make. Owner opens and funds a purse in one transaction:
test.transaction()
.allocate_component_address("alloc")
.call_function(template, "new", args![Workspace("alloc")])
.put_last_instruction_output_on_workspace("purse")
.call_method(owner.account, "withdraw", args![TARI_TOKEN, DEPOSIT])
.put_last_instruction_output_on_workspace("funds")
.call_method("purse", "deposit", args![Workspace("funds")])
.build_and_seal(&owner.secret)
The helper spends and keeps the receipt NFT in their own account:
test.transaction()
.call_method(purse, "spend", args![FORTY, cafe, "lunch".to_string()])
.put_last_instruction_output_on_workspace("receipt")
.call_method(bob.account, "deposit", args![Workspace("receipt")])
.build_and_seal(&bob.secret)
min(remaining, vault).