Skip to content

Transaction Builder

TransactionBuilder is a fluent, chainable API for constructing UnsignedTransactionV1 objects. Instructions are appended in order and executed as a single batch on-chain.

import { TransactionBuilder, Network, resolveMaxEpoch } from "@tari-project/ootle";
const builder = TransactionBuilder.new(Network.Esmeralda, await resolveMaxEpoch(provider));

Both arguments are required. The second is the transaction’s max_epoch — the last epoch in which it may be sequenced — which every transaction must carry. See Epoch Bounds.

A typical transaction: withdraw tokens from one account and deposit them into another.

const unsignedTx = TransactionBuilder.new(Network.Esmeralda, await resolveMaxEpoch(provider))
.feeTransactionPayFromComponent(accountAddress, 1000n)
.callMethod({ componentAddress: accountAddress, methodName: "withdraw" }, [
{ Literal: resourceAddress },
{ Literal: "500" },
])
.saveVar("bucket")
.callMethod({ componentAddress: recipientAddress, methodName: "deposit" }, [{ Workspace: "bucket" }])
.buildUnsignedTransaction();
MethodDescription
callFunction(func, args)Call a static function on a template
callMethod(method, args)Call a method on a component
createAccount(ownerPublicKey)Create a new account component
createProof(account, resource)Create a resource proof
claimBurn(claim)Claim a Minotari burn
saveVar(name)Save last output to workspace
feeTransactionPayFromComponent(addr, amount)Add fee instruction
feeTransactionPayFromComponentConfidential(addr, proof)Confidential fee
allocateAddress(type, name)Pre-allocate an address
setComponentAccessRules(addr, rules)Replace a component’s access rules
setComponentOwnerRule(addr, rule)Replace a component’s owner rule
addInput(req) / withInputs(reqs)Add substate inputs
withMinEpoch(n) / withMaxEpoch(n)Set epoch bounds
withNonce(n)Distinguish identical transactions
withMainSigner(mainSigner)Set the key the transaction acts as
withInstructions(instructions)Append raw instructions
withFeeInstructions(instructions)Append raw fee instructions
dropAllProofsInWorkspace()Drop all proofs
authorizeProof(name) / dropProofAuthorization(name)Open / close a proof’s auth window
withAuthorizedProof(name, build)Run build inside a proof’s window
buildUnsignedTransaction()Return the finished unsigned tx

Every transaction names its main signer: the key it acts as wherever the engine needs a single signer (OwnerRule::OwnedBySigner, a template’s transaction_signer_public_key, a published template’s author). The builder leaves it "None", and signTransaction replaces that with the first signer’s key ({ Authorizer: <public key hex> }).

Every signature covers the main signer, so when signatures are collected outside signTransaction (manual co-signing) set it with withMainSigner before the transaction leaves your hands.

A proof authorizes only inside a window the caller opens, and the window lends one hop: it covers the calls the enclosed instructions make, not calls those make in turn.

builder
.createProof(account, badgeResource)
.saveVar("badge")
.withAuthorizedProof("badge", (b) => b.callMethod({ componentAddress, methodName: "admin_only" }, []))
.dropAllProofsInWorkspace();

All methods return this, so you can chain calls. The builder mutates its internal state — each call appends to the same instruction list:

// These are equivalent:
const tx1 = builder.callMethod(a, argsA).callMethod(b, argsB).buildUnsignedTransaction();
builder.callMethod(a, argsA);
builder.callMethod(b, argsB);
const tx2 = builder.buildUnsignedTransaction();