Skip to main content
Build a token definition whose first owner text note increments a stored counter and ends the machine. The contract, machine, and embedded expression are supplied as complete files. The XML and core calculation have been tested locally with Waher.Script 2.15.0. Token creation and the first transition still need to be tested on your development Neuron.

Prerequisites

  • Complete contract authoring and submission.
  • Obtain an approved Creator Legal Identity, its signing key, and access to token and state-machine Agent API operations.
  • Confirm the provider supports this token creation vocabulary and the selected schema set.
  • Arrange the TrustProvider role, template approval, any creation charge, and the provider’s signing procedure. You cannot sign the provider’s role with your Creator key.
  • Confirm an accepted value, currency, commission percentage, and expiration date. Zero value in the sample request is a placeholder choice, not a guarantee of free creation.

1. Start with the complete definition

Save the complete definition below as note-token.xml, or download the XML file.
Three namespaces separate the contract, token creation instruction, and machine definition. Keep them exactly as supplied.

2. Understand the transition

The machine initializes Count to zero. In Waiting, OnTextNote invokes RecordNote. A successful action enters Complete; a failed action enters Failed. Both states invoke End.
This is a fragment inside the machine namespace. Script contains raw Neuron Script. The value attribute uses braces to evaluate an expression. NextCount is a calculation variable; PersistVariable records Count for subsequent machine state. An ordinary assignment alone does not replace that persistence step. The expected successful result is Count = 1. Later notes should not repeat this ended machine’s step. This is a design expectation to verify on your provider, not a general duplicate-event guarantee. Read Script syntax and execution contexts when changing the calculation. If you add a less-than comparison in an XML attribute, escape it as <.

3. Validate before proposing

Validate the complete file against the contract, token, and state-machine schemas, following local validation. Check that each state and action reference names a definition in the same machine. Expected result: the schema set compiles, the XML validates, and all explicit machine references resolve. The core expression Count:=0; NextCount:=Count+1; NextCount returns 1; see Script expressions. Neither check approves the template or runs the machine in its host context.

4. Obtain creation attributes and template approval

Send the following requests over HTTPS with your account’s exact host, JWT, and application URL as Referer. Replace every placeholder before sending a request.
Get Creation Attributes returns currency, commission, and trustProvider. A missing provider identity is a provisioning issue to resolve before creation. Confirm how these values apply to the accepted template and charges. Base64-encode the complete note-token.xml file’s UTF-8 bytes and propose it:
Record the returned Template identifier and follow the sandbox automatic review or operator approval process. Use Legal/GetContract with that identifier as contractId to observe the template lifecycle. Continue only with an approved, usable template. Template approval does not supply the TrustProvider signature required by this creation contract.

5. Create and sign the creation contract

Prepare the creation request:
  • Set the approved template ID.
  • Assign Creator to your approved Legal Identity and TrustProvider to the provider’s approved identity.
  • Set Value and CommissionPercent as JSON numbers. Replace the quoted commission placeholder with an actual number.
  • Set Currency to the accepted string and Expires to an ISO 8601 date-time accepted by the provider within the creation contract’s valid period.
  • Choose FriendlyName, from 1 to 80 characters.
Record the returned Contract ID. Retrieve the instance:
Have the Creator review the complete terms, parameters, and assigned role. After confirmation, calculate the contract signatures using the Creator’s key metadata, key password, account password, and a fresh nonce. Submit:
Retrieve the instance again with Legal/GetContract and the same contract ID. Coordinate the provider’s required signature separately. Observe all required signatures and the creation contract’s final state. Do not assume your first signature creates the token.

6. Find the created token

Retrieve tokens associated with the creation contract:
Inspect the returned Tokens structure for the token associated with this creation contract. Preserve the exact identifier. An empty list can mean creation is pending or failed; inspect the contract and provider result before submitting another creation request. Use the returned token identifier to retrieve the token and machine state:
Verify the token’s owner, creation contract, metadata, and current machine state. The expected starting machine state is Waiting with Count = 0. The state response contains CurrentState; use its returned structure rather than assuming an invented flat state field.

7. Send an owner note and observe the result

Send this request with the account that owns the token, using the same token ID. The request sets personal to false.
Repeat StateMachines/GetCurrentState above, and retrieve the event history:
The note response contains Note. A note being accepted is separate from confirming the intended machine outcome. Retrieve the state and event history until the provider’s documented completion window, with bounded polling in your application. For this example, verify Complete, the persisted Count = 1, and the corresponding note/action history. Record actual results and the Neuron build before treating the workflow as tested. If you receive Failed, preserve the returned diagnostic/history information and resolve the action failure before adapting the template.

Diagnose and adapt

When adapting this example, keep role references, parameter names, state IDs, and action references aligned. Update human-readable terms whenever automated behavior changes, validate the new file, and obtain a newly reviewed template when required by your provider. Retain the creation contract ID, token ID, template revision, input values, and observed state/history. Ending this custom machine does not itself destroy the token or delete its contract. Follow the asset’s supported expiration and retention rules; transfer and destruction require their own approved behavior.