Definition. The machine is optional. When present, the Trust Provider creates it as the token batch is created and links it to the creation contract and the first token in the batch.
Use a state machine when a token must react predictably to time, payments, contract signatures, notes, transfers, destruction, or persistent-data events.
Definition namespace
The root element uses the following schema namespace:startState, at least one State, and any referenced Action elements:
Create element of a smart contract; it is not a complete contract by itself. ISO 8601 duration PT1H means one hour.
Evaluation model
The machine follows this sequence:- Resolve initial variables from constants, token properties, token tags, or Script expressions.
- Enter
startStateand execute itsOnEnteraction references. - Register the active state’s event handlers.
- When an event matches, evaluate
beforeActionScript, runactionRef, and move tonewState. - Run the old state’s
OnLeaveactions and the new state’sOnEnteractions. - Sample the state and persisted variables unless sampling is explicitly suppressed.
OnEvent may set failureState for action failures and suppressSample when a transition should not create the normal audit sample. Treat both as advanced controls: hiding samples weakens the history available to reviewers.
Variables and values
Top-levelVariable elements initialize machine context. Their values can be:
- A token tag through
TagReference - A built-in token property through
TokenProperty - Typed literals:
String,Number,Boolean,Uri,Binary,Date,DateTime,Time, orDuration - A Script expression through
Calc
TokenId, CreatorJid, OwnerJid, TrustProviderJid, Value, Currency, Created, Updated, Expires, CreationContract, OwnershipContract, FriendlyName, Ordinal, and BatchSize.
Variables changed while an action runs are ephemeral unless the action uses PersistVariable. Persisted variables are sampled for audit and survive subsequent actions:
suppressSample only when a separate operation deliberately controls sampling.
Event types
Events can be declared inline underOnEvent, or declared once as an Event and reused through EventReference.
XML-note and contract events can filter on
localName and namespace. External-note events can also require a privilege; use that instead of accepting arbitrary external senders.
OnTime and OnDateTime accept time coordinates such as Local, UTC, or a quarter-hour UTC offset. Prefer UTC for workflows that cross legal or geographic boundaries.
Action types
AnAction is an ordered sequence. The schema supports:
- Payments:
Payment,ReserveAmount,ReleaseAmount,BuyEDaler, andSellEDaler - Notes and authorization:
TextNote,XmlNote,AuthorizeSource, andUnauthorizeSource - Communication:
HttpPost,XmppMessage,XmppIqGet,XmppIqSet, andMailMessage - Runtime data:
PersistVariable,CreateEntry,PersistHash, andLogEvent - Control flow:
If,IfHash,Switch,For,ForEach,While,Do, andTry/Catch/Finally - Composition and lifecycle:
Script,CallAction,ScheduleAction,End,Destroy, andFail
HttpPost and XMPP IQ can store their result in a named variable.
Singleton machines and token batches
One creation contract can produce a batch of tokens. The embedded definition creates one state-machine for that batch, not one independent machine per token. UseSingletonMachineId with a tag reference when multiple token creations must resolve to the same logical machine identifier.
Token properties such as Ordinal and BatchSize let actions reason about the current token in a batch.
Note commands
NoteCommand describes a client-facing command that generates a token note. It can provide localized Title, ToolTip, Confirmation, Success, and Failure text; typed parameters; a context Script; and a note-generation Script.
The flags determine where the generated note may be used:
ownerNote: add the note as the token owner.externalNote: submit it from an authorized external source.personal: mark the note as personal rather than generally visible.
Reports and inspection
Use the Agent API to inspect a running machine:- Get current state returns its current state.
- Create report produces present-state, history, diagram, or profiling output.
ReportPresent and ReportHistory Script templates to control human-readable report content.
Implementation checklist
- Validate the complete contract and embedded machine against their XML schemas.
- Confirm every
startState,newState,failureState,actionRef, andeventRefresolves. - Use explicit namespaces for XML and contract event filters.
- Persist only values required across actions; name audit-relevant values clearly.
- Decide how every remote call behaves on timeout, rejection, and retry.
- Generate present, history, state-diagram, and profiling reports in a staging environment.
- Exercise payment, signature, note, transfer, and terminal paths before signing the creation contract.