Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

⛓️Write the On-Chain Transfer Tool

Audience: Nexus adopters and integrators.

Goal: Build a Standard-mode Talus Agent Package (TAP) transfer Tool for disposable demonstration assets and understand why it is not an authorized production pattern.

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 its nexus_primitives and nexus_interface dependencies from the public primitives and interface 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 tool

transfer_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:

module tutorial_transfer::transfer_vertex;

use nexus_interface::onchain_tool_result::{Self as onchain_tool_result, OnchainToolResult};
use nexus_primitives::data;
use nexus_primitives::proof_of_uid::UIDRequirements;
use nexus_primitives::tagged_output;
use std::ascii::String as AsciiString;
use sui::transfer::public_transfer;
use tutorial_transfer::tutorial_transfer::{Self, TutorialState};

public struct TRANSFER_VERTEX has drop {}

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,
) {
    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: UIDRequirements and result: OnchainToolResult — supplied by the workflow. The Tool must 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_share combines it with the satisfied requirements in a durable OnchainToolResult that downstream vertices and nexus execution inspect can 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