⛓️Write the On-Chain Transfer Tool
The previous page set up TutorialState and the take_treasury helper. This page adds the actual Standard-mode on-chain Move Tool — a sibling module named transfer_vertex whose execute function the workflow invokes per skill execution.
The general mechanics of on-chain Move Tools (UIDRequirements, TaggedOutput, OnchainToolResult, witness types, and the registration round-trip) are covered in detail in the On-chain Tool Development guide. This consumer package installs nexus_primitives, nexus_interface, and nexus_workflow from the public primitives, interface, and workflow Move Registry records; use the public Nexus Move Packages source only for offline closure inspection or provenance. This page only walks through what's new for our TAP-bound transfer Tool.
1. Why a second Move module
The on-chain Tool the workflow calls is identified by (package_id, module_name, function_name). The module_name ends up as a registry key, so each on-chain Tool gets its own Move module. Our package will end up with two modules:
tutorial_transfer::tutorial_transfer // state + witness + helpers
tutorial_transfer::transfer_vertex // the on-chain vertex tooltransfer_vertex is what gets registered. The leader looks up transfer_vertex::execute by module + function name when it picks the walk up.
2. Add tap/sources/transfer_vertex.move
Drop the file alongside tutorial_transfer.move:
This complete example imports nexus_workflow from the public workflow Move Registry record. Include it with nexus_primitives and nexus_interface in the consumer package; it supplies the canonical DAGExecution type used by the guard.
module tutorial_transfer::transfer_vertex;
use nexus_interface::onchain_tool_result::{Self as onchain_tool_result, OnchainToolResult};
use nexus_interface::meta_schema;
use nexus_primitives::data;
use nexus_primitives::proof_of_uid::UIDRequirements;
use nexus_primitives::tagged_output;
use nexus_workflow::execution::DAGExecution;
use std::ascii::String as AsciiString;
use std::type_name;
use sui::transfer::public_transfer;
use tutorial_transfer::tutorial_transfer::{Self, TutorialState};
public struct TRANSFER_VERTEX has drop {}
const ENotWorkflowWorksheet: u64 = 0;
const EWrongExecution: u64 = 1;
const EAlreadyFinalized: u64 = 2;
const EInputCommitmentMismatch: u64 = 3;
fun assert_workflow_invocation(
requirements: &UIDRequirements,
result: &OnchainToolResult,
) {
let proof = requirements.proof();
assert!(
proof.type_name() == option::some(type_name::with_defining_ids<DAGExecution>()),
ENotWorkflowWorksheet,
);
assert!(proof.created_from() == onchain_tool_result::execution_id(result), EWrongExecution);
assert!(!onchain_tool_result::is_finalized(result), EAlreadyFinalized);
}
fun address_value(value: address): data::NexusValue {
let mut bytes = b"\"0x";
bytes.append(value.to_ascii_string().into_bytes());
bytes.append(b"\"");
data::inline_data_value(bytes)
}
fun assert_transfer_input_commitment(
result: &OnchainToolResult,
state: &TutorialState,
recipient: address,
) {
let state_value = data::object_value(object::id(state));
let recipient_value = address_value(recipient);
let actual = meta_schema::input_hash(
vector[b"0", b"1"],
vector[
meta_schema::port_commitment_one(&state_value),
meta_schema::port_commitment_one(&recipient_value),
],
);
assert!(actual == onchain_tool_result::input_commitment(result), EInputCommitmentMismatch);
}
public enum Output {
Transferred {
amount: u64,
recipient: address,
},
}
public fun fqn(): AsciiString {
tutorial_transfer::transfer_vertex_fqn()
}
/// On-chain transfer.
///
/// Inputs (the workflow passes these via the DAG entry ports):
/// requirements — workflow-supplied witness requirements.
/// result — workflow-supplied durable result object.
/// port 0 — `state: &mut TutorialState` (shared)
/// port 1 — `recipient: address`
///
/// The body drains the treasury, transfers the coin, satisfies the witness,
/// and finalizes a durable tagged result that the workflow records on chain.
public fun execute(
requirements: UIDRequirements,
result: OnchainToolResult,
state: &mut TutorialState,
recipient: address,
ctx: &mut TxContext,
) {
assert_workflow_invocation(&requirements, &result);
assert_transfer_input_commitment(&result, state, recipient);
let mut requirements = requirements;
let coin = tutorial_transfer::take_treasury(state);
let amount = coin.value();
public_transfer(coin, recipient);
tutorial_transfer::satisfy_transfer_vertex_requirement(state, &mut requirements);
let mut encoded_recipient = b"\"0x";
encoded_recipient.append(recipient.to_ascii_string().into_bytes());
encoded_recipient.append(b"\"");
let output = tagged_output::new(b"transferred")
.with_named_payload(
b"amount",
data::inline_data_value(amount.to_string().into_bytes()),
)
.with_named_payload(
b"recipient",
data::inline_data_value(encoded_recipient),
);
onchain_tool_result::finalize_and_share(result, requirements, output, ctx);
}3. What each line is doing
requirements: UIDRequirementsandresult: OnchainToolResult— supplied by the workflow. Before touching the treasury, the Tool proves that the worksheet came from the canonicalDAGExecution, that it and the result have the same execution ID, and that the result is not finalized. It recomputes the registered"0"state-object-ID and"1"canonical JSON-address commitments, in that order, and rejects a mismatch with the result. The Tool must also satisfy its registered witness and finalize the result; otherwise the workflow rejects the call or cannot consume its output.take_treasury+public_transfer— the actual SUI move. Once the walk succeeds the recipient owns those funds outright.tagged_output::new(b"transferred")— the transient structured output.finalize_and_sharecombines it with the satisfied requirements in a durableOnchainToolResultthat downstream vertices andnexus execution inspectcan observe.
4. Re-validate locally
Re-run the metadata validator, then compile and test the Move package to confirm both modules agree:
You should still see [✓] Validating TAP package skill config..., followed by a green Move build. Both modules are now present, and only the sibling Tool module can call the package-private treasury drain helper. The release TAP package has no Nexus-calling test in this step, so do not run its plain Move test as a substitute for the published-bytecode harness.
Run the separate move-tests-published/ arrangement from Build the TAP Move package when you need a published-Nexus check:
This local VM reads the selected public Nexus bytecode and overlays only test extensions; it does not publish, register, schedule, or move the tutorial treasury. The separate arrangement proves its published data call; use the public full-flow example for an on-chain Tool execute/authorization/result-finalization test. A successful local check still needs the publication, Tool registration, DAG/skill binding, and Testnet execution/readback steps on the following pages.
Next: DAG and skill config.
Last updated

