Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Tari Ootle development instructions for OpenAI Codex
Use these instructions to generate accurate Tari Ootle templates and client code aligned with repository APIs.
Overview
Tari Ootle is a decentralized application platform built on the Tari Layer 2 network. You build templates (smart contracts) in Rust, compile them to WASM (wasm32-unknown-unknown), publish them to the network, and interact with deployed components (instances of templates) via transactions.
Key concepts:
Template — A Rust module annotated with #[template] that defines the logic and state structure. Compiled to WASM and deployed to the network.
Component — A live instance of a template on-chain. Holds state (struct fields) and exposes public methods.
Resource — A native digital asset (fungible token or non-fungible NFT). Created with ResourceBuilder. Cannot be copied or accidentally destroyed.
Vault — An on-chain container that holds exactly one type of resource. Must be stored in a component before the function returns.
Bucket — A temporary container for resources during a transaction. Used to move assets between vaults or to/from method calls.
Transaction — A set of instructions (CallFunction, CallMethod, etc.) that are signed, submitted, and executed atomically.
Local test harness (dev-dependency): compile templates to WASM and run against the engine in-process
Tests only
Important macro distinction:
args! (from tari_template_lib::prelude) — used inside templates for cross-template calls (alias for invoke_args!)
args! (from tari_ootle_transaction) — used in test code and client code for TransactionBuilder, TemplateTest::call_function, and call_method. Produces Vec<NamedArg>.
Getting Started Workflow
The typical development workflow for building on Tari Ootle:
Generate a template project from the official starter repo:
Interact with your component using a client app built with ootle-rs, the Wallet CLI, or a pre-built example CLI from cargo generate.
Tip: For the guessing game and other example templates, pre-published template addresses are available on the Esmeralda testnet. Check the Tari Ootle guides for current addresses — you can skip publishing and go straight to interacting.
CLI App Workflow Order (IMPORTANT)
When running a CLI client app (e.g., the guessing game CLI), operations MUST happen in this order:
Initialize wallet — Create keypairs, select network, connect to indexer
Fund admin account — Get tTARI from the faucet
Publish the template — Deploy the WASM to the network. Direct the user to the Wallet Web UI at http://127.0.0.1:5100 to publish. Do NOT write custom publish code — the Web UI handles fee estimation, upload, and provides the template address.
Create/deploy the game component — Instantiate the template on-chain (requires the template address from step 3)
Register players — Add player accounts AFTER the game component exists
Play — Start rounds, make guesses, end games
CRITICAL: Never register players or add users before the template is published and the game component is deployed. Players need a component to interact with. Never try to publish a template programmatically unless the CLI already has a publish command — always direct users to the Wallet Web UI for publishing.
Tooling Requirements
The only tools needed for Ootle development are:
rustup with the wasm32-unknown-unknown target
cargo-generate (for scaffolding)
Standard Rust toolchain (cargo build, cargo test)
Do NOT install rust-analyzer extensions, cargo-expand, wasm-pack, wasm-bindgen, or other WASM/Rust analysis tools. They are unnecessary for Ootle development and add bloat. The wasm32-unknown-unknown target and standard cargo build are sufficient.
Non-Interactive CLI Usage
The generated CLI examples use dialoguer for interactive prompts (Select, Input), which requires a real TTY. Some agent runners execute commands in a non-interactive shell without a TTY.
When running CLI commands that have interactive prompts:
Tell the user to run the command in their terminal rather than trying to run it through the agent runner
Do NOT try to pipe input, use expect, or wrap with script — these are fragile workarounds
Do NOT modify the CLI to add non-interactive flags unless the user specifically asks for it
If the CLI already supports --flag style arguments that bypass prompts, use those
Writing a Template
Project Setup
# Install cargo-generate if not already installed
cargo install cargo-generate
# Generate a new template project from the official starter
cargo generate https://github.com/tari-project/wasm-template
The wasm-template repository offers multiple starting points:
wasm_templates/empty — A minimal blank template to start from scratch
examples/guessing_game/template — A complete guessing game template with tests
examples/guessing_game/cli — A ready-to-use CLI client for the guessing game
When you run cargo generate, select the subfolder that matches your goal. For a blank slate, choose a wasm_templates/ entry. For a working example to learn from, choose from examples/.
[package]name = "your_template"version = "0.1.0"edition = "2024"[dependencies]tari_template_lib = "0.20"[lib]crate-type = ["cdylib"]
[profile.release]opt-level = 's'# Optimize for size.lto = true# Enable Link Time Optimization.codegen-units = 1# Reduce number of codegen units to increase optimizations.panic = 'abort'# Abort on panic.strip = true# Strip symbols and debug info.
CRITICAL: The crate-type = ["cdylib"] is required for WASM compilation. Without it, the build will not produce a .wasm file.
Tip: The [profile.release] section in Cargo.toml significantly reduces the size of the compiled WASM file, which lowers the fees required for on-chain storage and publishing.
Versions: These crate versions are updated as new releases are published to crates.io. Use the minor version (e.g. "0.20" not "0.20.5") to automatically get the latest patch. Before starting a new template, check crates.io for a newer minor version (e.g. "0.21", "0.22").
Compilation
# Add the WASM target (one-time setup)
rustup target add wasm32-unknown-unknown
# Build the template
cargo build --target wasm32-unknown-unknown --release
use tari_template_lib::prelude::*;
#[template]mod my_template {
use super::*;
// Component state — all fields must be serde-serializablepubstructMyComponent {
my_vault: Vault,
counter: u64,
}
implMyComponent {
// CONSTRUCTOR: any function returning Self or Component<Self>// creates a new component instance on-chain when called via CallFunctionpubfnnew() -> Component<Self> {
lettoken = ResourceBuilder::public_fungible()
.with_token_symbol("TOK")
.build(); // → ResourceAddress
Component::new(Self {
my_vault: Vault::new_empty(token),
counter: 0,
})
.with_access_rules(
ComponentAccessRules::new()
.method("public_method", rule!(allow_all))
.default(rule!(deny_all))
)
.create()
}
// PUBLIC METHOD: takes &self or &mut self, called via CallMethodpubfnpublic_method(&mutself, value: u64) {
self.counter += value;
}
// READ-ONLY METHOD: takes &self, cannot modify statepubfnget_counter(&self) ->u64 {
self.counter
}
// FUNCTION (no &self): called via CallFunction on the template, not a method on a componentpubfngreet(name: String) ->String {
format!("Hello, {}!", name)
}
}
// Private helper: no &self, not in impl block's public interfacefninternal_helper() ->u64 {
42
}
}
The #[template] Macro
Generates the WASM ABI so the validator engine can call your code
Exposes public functions in impl blocks as callable methods/functions
Handles state serialization/deserialization automatically
Structs defined inside the #[template] module automatically get serde derives
Only one #[template] module per crate
Component State Rules
All struct fields MUST be serde-serializable (types from tari_template_lib already are)
Use &mut self methods to modify state
Use &self methods for read-only access
A component can also be an enum
State size affects transaction costs
Supported field types: all Rust primitives, String, Vec<T>, HashMap<K,V>, BTreeMap<K,V>, Option<T>, Vault, Amount, ResourceAddress, ComponentAddress, RistrettoPublicKeyBytes, NonFungibleId, ComponentManager, and any struct inside the #[template] module
Constructors
// Simple constructor — returning Self creates the component with default rulespubfnnew_simple() ->Self {
Self { counter: 0 }
}
// Explicit constructor — returns Component<Self> for full controlpubfnnew_explicit() -> Component<Self> {
Component::new(Self { counter: 0 })
.with_access_rules(ComponentAccessRules::new()
.method("do_something", rule!(allow_all))
.default(rule!(deny_all))
)
.with_owner_rule(OwnerRule::OwnedBySigner)
.create()
}
// Constructor with address allocation — allows creating and calling in one transactionpubfnnew_with_allocation(addr: ComponentAddressAllocation) -> Component<Self> {
Component::new(Self { counter: 0 })
.with_address_allocation(addr)
.with_access_rules(ComponentAccessRules::new()
.method("do_something", rule!(allow_all))
.default(rule!(deny_all))
)
.create()
}
// Constructor with public key address — deterministic address from a public keypubfnnew_with_public_key() -> Component<Self> {
letpk = CallerContext::transaction_signer_public_key();
Component::new(Self { counter: 0 })
.with_public_key_address(pk)
.with_access_rules(ComponentAccessRules::allow_all())
.create()
}
Error Handling
Errors in templates are handled by panicking. When a panic occurs, the transaction fails atomically and no state changes are committed:
pubfndo_something(&mutself, value: u64) {
assert_ne!(value, 0, "Value cannot be zero");
assert!(value <= 1024, "Value too large");
if !value.is_power_of_two() {
panic!("Value must be a power of two");
}
self.counter += value;
}
There are no Result-based error flows in templates. Panics are the error mechanism.
Resources
There are 4 resource types:
Public Fungible — Interchangeable tokens (like ERC-20), amounts visible on-chain
Public Non-Fungible — Unique tokens (like ERC-721), metadata visible on-chain
Confidential — Fungible tokens with hidden amounts (Pedersen commitments)
Stealth — Confidential UTXOs with hidden owners (TARI/tTARI is a stealth resource)
Creating Resources
// ─── Public Fungible Token ───// Without initial supply → returns ResourceAddresslettoken_addr: ResourceAddress = ResourceBuilder::public_fungible()
.with_token_symbol("TOK")
.metadata("name", "My Token")
.build();
// With initial supply → returns Bucket containing tokenslettoken_bucket: Bucket = ResourceBuilder::public_fungible()
.with_token_symbol("TOK")
.metadata("name", "My Token")
.initial_supply(Amount::from(1000))
.build();
// ─── Non-Fungible (NFT) ───letnft_addr: ResourceAddress = ResourceBuilder::non_fungible()
.with_token_symbol("NFT")
.metadata("name", "My NFT Collection")
.build(); // Mint later via ResourceManager// With initial supply of NFTsletnft_bucket: Bucket = ResourceBuilder::non_fungible()
.with_token_symbol("NFT")
.initial_supply_with_data(vec![
(NonFungibleId::from_u64(1), &metadata!["name" => "First"], &()),
(NonFungibleId::from_u64(2), &metadata!["name" => "Second"], &()),
])
.build();
// ─── Confidential Fungible ───letconf_addr: ResourceAddress = ResourceBuilder::confidential()
.with_token_symbol("cTOK")
.with_view_key(CallerContext::transaction_signer_public_key())
.build();
// ─── Stealth (like TARI) ───letstealth_addr: ResourceAddress = ResourceBuilder::stealth()
.with_token_symbol("sTOK")
.build();
Resource Builder Options (All Types)
ResourceBuilder::public_fungible() // or non_fungible(), confidential(), stealth()// Metadata
.with_token_symbol("SYM") // Token symbol (displayed by explorers)
.metadata("name", "Token Name") // Add metadata key-value pair
.add_metadata("key", "value") // Same as .metadata()// Access rules on the resource itself
.mintable(rule!(resource(admin_badge))) // Who can mint new tokens (default: deny_all)
.burnable(rule!(allow_all)) // Who can burn tokens (default: deny_all)
.recallable(rule!(deny_all)) // Who can forcefully recall from vaults
.freezable(rule!(deny_all)) // Who can freeze vaults holding this resource
.withdrawable(rule!(allow_all)) // Who can withdraw (default: allow_all)
.depositable(rule!(allow_all)) // Who can deposit (default: allow_all)
.update_non_fungible_data(rule!(...)) // Who can update NFT mutable data
.update_access_rules(rule!(...)) // Who can change these rules later// Ownership
.with_owner_rule(OwnerRule::OwnedBySigner) // Owner of the resource definition// Advanced
.with_divisibility(2) // Fungible only: decimal places (default: 0)
.disable_total_supply_tracking() // Don't track total supply on-chain
.with_address_allocation(alloc) // Pre-allocated resource address// Finalize
.build() // Create the resource (returns ResourceAddress)
.initial_supply(Amount::from(1000)) // Mint initial tokens (changes return to Bucket)
Minting NFTs After Creation
letmanager: ResourceManager = vault.get_resource_manager();
// Mint a single NFTletnft_bucket: Bucket = manager.mint_non_fungible(
NonFungibleId::from_string("unique-id"), // Unique ID within this resource
&metadata!["name" => "My NFT"], // Immutable data (cannot change after mint)
&(), // Mutable data (can be updated later)
);
// NonFungibleId variants:
NonFungibleId::from_string("my-id") // String (max 64 chars)
NonFungibleId::from_u64(42) // u64
NonFungibleId::from_u32(1) // u32
NonFungibleId::from_u256([0u8; 32]) // 32-byte array
NonFungibleId::random() // Random UUID-style
Vaults — Complete API
// ─── Creation ───letvault = Vault::new_empty(resource_address); // Empty vault for a resource typeletvault = Vault::from_bucket(bucket); // Create vault containing bucket's tokens// ─── Deposits ───
vault.deposit(bucket); // Add tokens from bucket into vault// ─── Withdrawals ───letbucket = vault.withdraw(amount); // Withdraw fungible amount → Bucketletbucket = vault.withdraw(1u64); // Can pass u64 directlyletbucket = vault.withdraw_non_fungible(nft_id); // Withdraw one NFT by ID → Bucketletbucket = vault.withdraw_non_fungibles(id_set); // Withdraw multiple NFTs → Bucketletbucket = vault.withdraw_all(); // Withdraw everything → Bucket// ─── Queries ───letbalance: Amount = vault.balance(); // Current balanceletlocked: Amount = vault.locked_balance(); // Locked/frozen balanceletaddr: ResourceAddress = vault.resource_address();// Resource type held by this vaultletids: BTreeSet<NonFungibleId> = vault.get_non_fungible_ids(); // All NFT IDs in vault// ─── Resource Management ───letmanager: ResourceManager = vault.get_resource_manager(); // For minting etc.// ─── Fee Payment ───
vault.pay_fee(amount); // Pay transaction fee from this vault// ─── Authorization ───
vault.authorize(); // Create auth proof from vault contents (RAII)letproof = vault.create_proof_by_amount(amount); // Create proof for a specific amount
CRITICAL: A Vault MUST be stored in a component struct field before the function returns. An orphaned vault (created but not stored) will cause the transaction to fail.
Buckets — Complete API
// ─── Queries ───letaddr: ResourceAddress = bucket.resource_address(); // What resource this holdsletrtype: ResourceType = bucket.resource_type(); // Fungible, NonFungible, etc.letamt: Amount = bucket.amount(); // How many tokensletempty: bool = bucket.is_empty(); // Whether emptyletids = bucket.get_non_fungible_ids(); // NFT IDs in bucketletnfts = bucket.get_non_fungibles(); // Full NFT data// ─── Splitting ───letnew_bucket = bucket.take(Amount::from(50)); // Split off some tokens// ─── Combining ───letcombined = bucket.join(other_bucket); // Merge two same-resource buckets// ─── Destruction ───
bucket.burn(); // Permanently destroy tokens
bucket.drop_empty(); // Assert empty and drop (panics if not)// ─── Proofs ───letproof = bucket.create_proof(); // Create ownership proof
CRITICAL: A Bucket MUST be consumed before the function returns. Consume it by: depositing into a vault, burning, returning from a function, or passing to another component. An orphaned bucket will cause the transaction to fail.
Access Rules and Authorization
Component Access Rules
Component::new(Self { ... })
.with_access_rules(
ComponentAccessRules::new() // Default: deny_all for unlisted methods
.method("guess", rule!(allow_all))
.method("admin_action", rule!(resource(admin_badge)))
.default(rule!(deny_all))
)
// OR use the convenience constructor:// ComponentAccessRules::allow_all() // Default: allow_all for unlisted methods
.with_owner_rule(OwnerRule::OwnedBySigner)
.create()
The rule! Macro — Complete Reference
// ─── Basic Rules ───
rule!(allow_all) // No restrictions
rule!(deny_all) // Nobody can call// ─── Resource-Based Rules ───
rule!(resource(resource_address)) // Must hold this resource in a proof
rule!(non_fungible(NonFungibleAddress::new(res, id))) // Must hold specific NFT
rule!(public_key(ristretto_public_key_bytes)) // Must be signed by this key// ─── Scope Rules ───
rule!(component(component_address)) // Only callable from this component
rule!(template(template_address)) // Only callable from this template// ─── Composite Rules ───
rule!(any_of(resource(a), resource(b))) // Any one condition met (OR)
rule!(all_of(resource(a), resource(b))) // All conditions met (AND)
rule!(m_of_n(2, resource(a), resource(b), resource(c)))// M of N conditions met
Owner Rules
OwnerRule::OwnedBySigner // Default: transaction signer is owner
OwnerRule::None// No owner (nobody can update access rules)
OwnerRule::ByAccessRule(rule) // Custom rule determines ownership
OwnerRule::ByPublicKey(pk) // Specific public key is owner
Caller Context — Complete API
// Get the authenticated signer (ALWAYS use this for identity, never accept as argument)letsigner: RistrettoPublicKeyBytes = CallerContext::transaction_signer_public_key();
// Get current component address (only in CallMethod context)letaddr: ComponentAddress = CallerContext::current_component_address();
// Get signer proof (for passing as authorization)letproof: Proof = CallerContext::get_main_signer_proof();
letproof: Proof = CallerContext::get_signer_proof_for_public_key(pk);
// Address allocation (for creating components/resources with deterministic addresses)letalloc: ComponentAddressAllocation = CallerContext::allocate_component_address(None);
letalloc: ComponentAddressAllocation = CallerContext::allocate_component_address(Some(pk));
letalloc: ResourceAddressAllocation = CallerContext::allocate_resource_address();
NEVER accept a public key as a method argument for authentication. Always use CallerContext::transaction_signer_public_key() — it cannot be spoofed.
Cross-Component Calls
// Get a reference to another componentletother: ComponentManager = ComponentManager::get(component_address);
// Call a method that returns a valueletvalue: u64 = other.call("method_name", args![arg1, arg2]);
// Call a method that returns unit (fire-and-forget)
other.invoke("method_name", args![arg1, arg2]);
// Common pattern: deposit a bucket into another component (e.g., Account)
other.invoke("deposit", args![prize_bucket]);
// Get template address of a componentlettmpl: TemplateAddress = other.get_template_address();
// Get the addressletaddr: ComponentAddress = other.component_address();
Events
// Emit an event (permanently recorded in the transaction receipt)emit_event("GameEnded", metadata![
"winner_account" => winner_address.to_string(),
"number" => winning_number.to_string(),
"round" => round.to_string(),
]);
Events are indexed by the Indexer and can be queried by explorers and dApps. The topic is formatted as "TemplateName.EventTopic" in receipts.
Randomness
use tari_template_lib::rand::random_bytes;
// Get N pseudorandom bytesletbytes: Vec<u8> = random_bytes(4);
// Convenience: get a random u32use tari_template_lib::rand::random_u32;
letn: u32 = random_u32();
// Common pattern: random number in rangefngenerate_number() ->u8 {
random_bytes(1)[0] % 11// 0..=10
}
WARNING:random_bytes is deterministic — entropy comes from the transaction itself to ensure all validators produce the same result. Do NOT use for cryptographic security. You cannot use the rand crate in templates (no entropy source on wasm32-unknown-unknown).
Publishing Templates
STOP: Do NOT write a publish command. When the user needs to publish a template, tell them to use the Wallet Web UI. Do NOT add a publish subcommand to CLI apps, do NOT write publish_template() code, do NOT try to create a programmatic publish workflow. The Web UI at http://127.0.0.1:5100 is the correct and only supported way to publish templates.
Publish via Wallet Web UI (The Only Supported Method)
Open the Tari Ootle Wallet web UI (default: http://127.0.0.1:5100)
Click "Publish Template" on the Home page
Select fee account with tTARI (testnet Tari)
Upload the .wasm file from target/wasm32-unknown-unknown/release/
Click "Estimate Fee" then "Publish Template"
Find the template address under "Templates" in the sidebar
Paste the template address into the CLI's state file or --template-address flag
Publish Programmatically (ootle-rs) — Reference Only
This section is reference documentation for existing publish implementations. Do NOT use this to write new publish commands — direct users to the Web UI instead.
use tari_ootle_transaction::TransactionBuilder;
use ootle_rs::TransactionRequest;
letwasm_binary: Vec<u8> = std::fs::read("target/wasm32-unknown-unknown/release/your_template.wasm")?;
letunsigned = TransactionBuilder::new(provider.network())
.with_auto_fill_inputs()
.pay_fee_from_component(account_addr, 250_000u64) // See fee note below
.publish_template(wasm_binary.try_into().unwrap())
.build_unsigned();
lettx = TransactionRequest::default()
.with_transaction(unsigned)
.build(provider.wallet())
.await?;
letreceipt = provider.send_transaction(tx).await?.watch().await?;
// Get the new template address from the receiptlettemplate_addr = receipt.diff_summary.upped
.iter()
.find_map(|s| s.substate_id.as_template())
.expect("template address in receipt");
Fee guidance for publishing: Template publishing fees are proportional to WASM binary size. A typical template (~100-300 KB) needs 150,000-250,000 fee units. If you get an "insufficient fees" error, increase the fee amount. You can use the Wallet Web UI's "Estimate Fee" button to get an accurate estimate before publishing.
Interacting with Deployed Components (Client-Side Rust)
Setup Wallet and Provider
use ootle_rs::{
key_provider::PrivateKeyProvider,
provider::ProviderBuilder,
wallet::OotleWallet,
default_indexer_url,
};
use tari_ootle_common_types::Network;
const NETWORK: Network = Network::Esmeralda; // Testnet (default_indexer_url is configured)// Create a random wallet (for testing) or load from seedletsecret = PrivateKeyProvider::random(NETWORK);
letwallet = OotleWallet::from(secret);
letmut provider = ProviderBuilder::new()
.wallet(wallet)
.connect(default_indexer_url(NETWORK))
.await?;
// With custom transaction timeout (default is 32 seconds — too short for testnet):use std::time::Duration;
letmut provider = ProviderBuilder::new()
.wallet(wallet)
.connect_with_transaction_timeout(default_indexer_url(NETWORK), Duration::from_secs(120))
.await?;
Timeout guidance: The default transaction timeout is 32 seconds, which is often too short for the Esmeralda testnet. Use connect_with_transaction_timeout() with 120 seconds for testnet usage. LocalNet is faster and the default is usually fine.
Available networks:
Network::Esmeralda — Public testnet (indexer: http://217.182.93.35:50124)
Network::LocalNet — Local development (indexer: http://localhost:12500)
Other networks (MainNet, StageNet, NextNet, Igor) are not yet configured with default indexer URLs
Fund Account (Testnet Faucet)
use ootle_rs::{
TransactionRequest,
builtin_templates::{UnsignedTransactionBuilder, faucet::IFaucet},
};
use tari_template_lib_types::constants::TARI;
letunsigned_tx = IFaucet::new(&provider)
.take_faucet_funds(10 * TARI) // Request 10 TARI
.pay_fee(500u64) // Fee for the transaction
.prepare()
.await?;
lettx = TransactionRequest::default()
.with_transaction(unsigned_tx)
.build(provider.wallet())
.await?;
letpending = provider.send_transaction(tx).await?;
letoutcome = pending.watch().await?;
Transaction Pattern (Sign → Send → Watch)
Every on-chain interaction follows this pattern:
use tari_ootle_transaction::{TransactionBuilder, args};
use ootle_rs::TransactionRequest;
// 1. Build an unsigned transactionletunsigned_tx = TransactionBuilder::new(provider.network())
.with_auto_fill_inputs() // Auto-detect input substates
.pay_fee_from_component(account_addr, 2000u64) // Pay fee from account
.call_function(template_addr, "new", args![]) // Or call_method(...)
.build_unsigned();
// 2. Sign itlettx = TransactionRequest::default()
.with_transaction(unsigned_tx)
.build(provider.wallet())
.await?;
// 3. Send and wait for finalizationletpending = provider.send_transaction(tx).await?;
letreceipt = pending.watch().await?;
TransactionBuilder::new(network)
// Input handling
.with_auto_fill_inputs() // Auto-detect required substates
.add_input(substate_address) // Add specific input
.with_inputs(iter_of_inputs) // Add multiple inputs
.with_unversioned_inputs(iter) // Add unversioned inputs// Fee payment
.pay_fee_from_component(account, amount) // Pay fee from an account component
.pay_fee_from_bucket(bucket_label, amount) // Pay fee from a workspace bucket// Instructions
.call_function(template, "fn_name", args![...]) // Call template function
.call_method(component, "method", args![...]) // Call component method
.create_account(public_key) // Create an account component
.create_account_with_bucket(pk, bucket_label) // Create account with initial funds
.publish_template(wasm_binary) // Deploy a template// Workspace (chain instruction outputs)
.put_last_instruction_output_on_workspace("label") // Store output for later use
.take_from_bucket("label", amount) // Take from workspace bucket// Address allocation
.allocate_component_address() // Pre-allocate component address
.allocate_resource_address() // Pre-allocate resource address// Build
.build_unsigned() // Produce unsigned transaction
Read Addresses from Receipts
// Find the new component addressletcomponent_addr = receipt.diff_summary.upped
.iter()
.find_map(|s| s.substate_id.as_component_address())
.expect("component address in receipt");
// Find a resource address (excluding native TARI)use tari_template_lib_types::constants::TARI_TOKEN;
letresource_addr = receipt.diff_summary.upped
.iter()
.find_map(|s| s.substate_id.as_resource_address().filter(|a| *a != TARI_TOKEN))
.expect("resource address in receipt");
// Find a template address (returns PublishedTemplateAddress)// IMPORTANT: Use as_template() on SubstateId — NOT as_template_address()// as_template_address() does NOT exist on SubstateIdlettemplate_addr = receipt.diff_summary.upped
.iter()
.find_map(|s| s.substate_id.as_template())
.expect("template address in receipt");
IMPORTANT API note: On SubstateId, the method is as_template() — it returns Option<PublishedTemplateAddress>. There is NO as_template_address() method on SubstateId. If you need the underlying TemplateAddress (a Hash32), call .as_template_address() on the PublishedTemplateAddress result, not on the SubstateId.
Use tari_template_test_tooling as a dev-dependency. It compiles your template to WASM and runs transactions against it locally using the same execution engine as the network.
Versions: These versions may be updated as new crates are published. Use the minor version (e.g. "0.25" not "0.25.7") to get the latest patch. Check crates.io for newer versions before starting.
Standard Test Pattern
Most template interactions require multiple instructions in a single transaction (e.g. creating a component then calling a method on it, or paying fees from an account). Use test.transaction() to build multi-instruction transactions — this is the standard way to write tests.
use tari_template_test_tooling::TemplateTest;
use tari_ootle_transaction::args;
#[test]fntest_my_template() {
letmut test = TemplateTest::new(".", ["."]);
let (account, owner_proof, secret_key) = test.create_funded_account();
lettemplate_addr = test.get_template_address("MyTemplate");
// Build a transaction with multiple instructionslettransaction = test.transaction()
.call_function(template_addr, "new", args![])
.put_last_instruction_output_on_workspace("component")
.call_method("component", "some_method", args![42u64])
.build_and_seal(&secret_key);
letresult = test.execute_expect_success(transaction, vec![owner_proof]);
}
TemplateTest — Key Methods
// ─── Construction ───
TemplateTest::my_crate() // Test the template in the current crate
TemplateTest::new(base_path, [paths]) // Compile templates from given paths
TemplateTest::new_builtin_only() // Only built-in templates (Account, etc.)// ─── Building Transactions ───lettx = test.transaction() // Returns a transaction builder (recommended)
.call_function(template_addr, "fn", args![...])
.put_last_instruction_output_on_workspace("name")
.call_method("name", "method", args![...])
.build_and_seal(&secret_key);
// ─── Single-Call Convenience Methods ───// Each creates a transaction with a single call. Useful for simple cases but limited —// Most template interactions require multiple instructions to be useful (e.g. deposit a bucket// returned from a previous call). Use test.transaction() for this.letresult: T = test.call_function("TemplateName", "function", args![...], proofs);
letresult: T = test.call_method(component_addr, "method", args![...], proofs);
// ─── Account Management ───let (account, proof, secret) = test.create_funded_account(); // 1B micro-TARI balancelet (account, proof, secret) = test.create_empty_account();
// ─── Execution ───letresult = test.execute_expect_success(transaction, proofs); // Panics on failureletresult = test.execute_expect_failure(transaction, proofs); // Panics on successletresult = test.execute_expect_commit(transaction, proofs); // Panics if not finalized// ─── State Inspection ───letvalue: T = test.extract_component_value(component_addr, "field_path");
letaddr = test.get_template_address("TemplateName");
// ─── Configuration ───
test.enable_fees(); // Enable fee tracking
test.disable_fees(); // Disable fee tracking (default)
Tari Wallet CLI
The tari_ootle_wallet_cli is a simple CLI for interacting with the Wallet Daemon (tari_ootle_walletd) via its JSON-RPC interface. The wallet daemon is what connects to the network via the indexer.
Repository: This CLI is part of the tari-ootle repository at applications/tari_wallet_cli/.
Building from source:
cargo build --release --bin tari_ootle_wallet_cli
Pre-built binaries are available on the releases page.
Connection
# Connect to a wallet daemon (default endpoint)
tari_ootle_wallet_cli -d /ip4/127.0.0.1/tcp/12009 <command>
# Or via environment variableexport JRPC_ENDPOINT="/ip4/127.0.0.1/tcp/12009"
tari_ootle_wallet_cli <command>
Account Commands
# Create a new account
tari_ootle_wallet_cli accounts create --name "my-account"# List all accounts
tari_ootle_wallet_cli accounts list
# Get account details
tari_ootle_wallet_cli accounts get my-account
# Check balances
tari_ootle_wallet_cli accounts get-balance my-account
# Get free testnet tokens (faucet)
tari_ootle_wallet_cli accounts faucet my-account --amount 1000000
# Set default account
tari_ootle_wallet_cli accounts default my-account
Transaction Commands
# Call a template function (e.g., create a component)
tari_ootle_wallet_cli transactions submit call-function \
<template_address> new \
--fee-account my-account \
--wait-timeout 30
# Call a component method with arguments
tari_ootle_wallet_cli transactions submit call-method \
<component_address> guess \
-a 5 -a <payout_component_address> \
--fee-account my-account
# Submit a transaction manifest (advanced)
tari_ootle_wallet_cli transactions submit-manifest manifest.tari \
--fee-account my-account
# Get transaction result
tari_ootle_wallet_cli transactions get <transaction_id>
# Send tokens to another account
tari_ootle_wallet_cli transactions send \
1000 <resource_address> <destination_pubkey> \
--fee-account my-account
# Confidential transfer
tari_ootle_wallet_cli transactions confidential-transfer \
1000 <destination_ootle_address> \
--account my-account
Key Management
tari_ootle_wallet_cli keys list
tari_ootle_wallet_cli keys create
use tari_template_lib::prelude::*;
#[template]mod guessing_game {
use std::{collections::HashMap, mem};
use super::*;
const MAXIMUM_GUESSES_PER_ROUND: usize = 5;
pubstructGuessingGame {
prize_vault: Vault,
guesses: HashMap<RistrettoPublicKeyBytes, Guess>,
round_number: u32,
}
pubstructGuess {
pub payout_to: ComponentManager,
pub guess: u8,
}
implGuessingGame {
pubfnnew(address: ComponentAddressAllocation) -> Component<Self> {
letprize_resource = ResourceBuilder::non_fungible()
.metadata("name", "Guessing Game Prize")
.with_token_symbol("DICE")
.build();
letaccess_rules = ComponentAccessRules::new()
.method("guess", rule!(allow_all));
Component::new(Self {
prize_vault: Vault::new_empty(prize_resource),
guesses: HashMap::new(),
round_number: 0,
})
.with_address_allocation(address)
.with_access_rules(access_rules)
.create()
}
pubfnstart_game(&mutself, prize: NonFungibleId) {
assert!(!self.is_game_in_progress(), "Game already in progress!");
self.round_number += 1;
letmanager = self.prize_vault.get_resource_manager();
letprize = manager.mint_non_fungible(
prize,
&metadata!["round" => self.round_number.to_string()],
&(),
);
self.prize_vault.deposit(prize);
}
pubfnguess(&mutself, guess: u8, payout_to: ComponentAddress) {
assert!(guess <= 10, "Guess must be from 0 to 10");
assert!(self.guesses.len() < MAXIMUM_GUESSES_PER_ROUND, "No more guesses allowed");
assert!(self.is_game_in_progress(), "No game has been started");
letplayer = CallerContext::transaction_signer_public_key();
letpayout_to = ComponentManager::get(payout_to);
letprev = self.guesses.insert(player, Guess { payout_to, guess });
assert!(prev.is_none(), "You already guessed in this round");
}
pubfnend_game_and_payout(&mutself) {
letprize = self.prize_vault.withdraw(1u64);
letnumber = generate_number();
letguesses = mem::take(&mutself.guesses);
letnum_participants = guesses.len();
for (player, guess) in guesses {
if guess.guess == number {
guess.payout_to.invoke("deposit", args![prize]);
emit_event("GameEnded", metadata![
"winner" => player.to_string(),
"winner_account" => guess.payout_to.component_address().to_string(),
"number" => number.to_string(),
"num_participants" => num_participants.to_string(),
]);
return;
}
}
emit_event("GameEnded", metadata![
"number" => number.to_string(),
"num_participants" => num_participants.to_string(),
]);
prize.burn();
}
fnis_game_in_progress(&self) ->bool {
!self.prize_vault.balance().is_zero()
}
}
fngenerate_number() ->u8 {
use tari_template_lib::rand::random_bytes;
random_bytes(1)[0] % 11
}
}
Common Mistakes to Avoid
Orphaned Vault — Creating a Vault but not storing it in a component field → transaction fails.
Orphaned Bucket — Not consuming a Bucket (deposit, burn, or return it) → transaction fails.
Spoofable Auth — Accepting a public key as a function argument for identity → use CallerContext::transaction_signer_public_key().
Wrong rand — Using the rand crate → use tari_template_lib::rand::random_bytes (no entropy on wasm32).
No Access Rules — Forgetting .with_access_rules() → default is deny_all, only the component creator/owner can call methods.
Wrong Resource in Vault — Depositing a different resource type into a vault → transaction fails.
Missing cdylib — Forgetting crate-type = ["cdylib"] in Cargo.toml → no WASM output produced.
Using the wrong args! macro — Ensure you use args! from tari_ootle_transaction for client/test code (produces Vec<NamedArg>) and args! from tari_template_lib::prelude for cross-template calls inside templates.
Returning mutable bucket — Forgetting to actually deposit/burn a bucket in all code paths → transaction fails if the bucket isn't consumed.
Large state — Storing unbounded data structures → high transaction costs, potential DoS.
Hallucinated APIs — These methods/types do NOT exist. Never use them:
SubstateId::as_template_address() — use as_template() instead
IAccount::publish_template() — no such method; publish via TransactionBuilder::publish_template() or the Web UI
provider.publish_template() — no such method on the provider
ProviderBuilder::with_timeout() — use connect_with_transaction_timeout() instead
Writing publish commands — Do NOT write custom template publish code. Direct users to the Wallet Web UI. The generated CLI examples do not include a publish command by design.
Wrong operation order — Always: init wallet → fund → publish template → create component → register players. Never register players before the game component exists.
Struct placement in template module — The #[template] macro requires the main component struct to appear first in the template module. Placing other structs above it causes the macro to treat the wrong struct as the component, leading to compilation errors like "a template must have associated functions and/or methods". Fix: define ancillary structs in their own module and use them, or place them below the component impl block. Note: ancillary structs defined outside the template module must derive #[derive(serde::Serialize, serde::Deserialize)] and require serde = "1" as a dependency.
Git dependencies — Never use git dependencies in Cargo.toml. All Tari crates are published on crates.io. Always use the latest minor version (e.g. "0.20" not a git URL). Check crates.io if unsure.
Duplicate test dependency — tari_template_test_tooling re-exports the tari_ootle_transaction crate. Use the re-export (tari_template_test_tooling::transaction) in tests rather than adding tari_ootle_transaction as a separate [dev-dependencies] entry.
Missing standard imports — Import standard library types (e.g. HashMap, BTreeMap) as normal in Rust. You can import them outside the template module and bring them in with use super::*; (which all template modules should include), or import directly inside the template module.
Quick Reference: Prelude Exports
The tari_template_lib::prelude::* import gives you: