Sui.

Post

Share your knowledge.

harry phan.
Jul 15, 2025
Expert Q&A

How can I call from a node js app using SUI TS SDK

Here is a snippet of a Sui move

public enum Category has copy, drop, store {
        A,
        B,
        C
    }
public entry fun process_categories(categories: vector<Category>, ctx: &mut TxContext)

How can I call from a node js app using SUI TS SDK, to call the process_categories function, specifically send categories as an argument?

  • Sui
0
1
Share
Comments
.

Answers

1
24p30p.
Jul 15 2025, 07:22

To call your process_categories function from a Node.js app using the Sui TypeScript SDK, you need to pass the categories argument as a vector of enum values in a Move-compliant format. Here's how to do that properly using the SDK:


✅ Full Example Using Sui TS SDK

import { SuiClient, TransactionBlock } from "@mysten/sui.js/client";
import { Ed25519Keypair } from "@mysten/sui.js/keypairs";
import { fromB64 } from "@mysten/bcs";

// Setup your client and keypair
const keypair = Ed25519Keypair.deriveKeypair("your mnemonic or private key");
const suiClient = new SuiClient({ url: "https://fullnode.devnet.sui.io" });

// Build transaction
const tx = new TransactionBlock();

// Define enum variants
const categories = ["A", "B", "C"]; // example Move enum values

// Encode the enum values using bcs
const bcs = tx.bcs;
const CategoryEnum = bcs.enum("Category", {
  A: null,
  B: null,
  C: null,
});

// Register Category type
bcs.registerEnumType("Category", {
  A: null,
  B: null,
  C: null,
});

// Encode enum vector
const encoded = bcs.vector(CategoryEnum).serialize(categories.map((cat) => ({ [cat]: null }))).toBase64();

// Call your move function with serialized vector
tx.moveCall({
  target: "0xYourPackage::YourModule::process_categories",
  arguments: [
    tx.pure(encoded, "vector<Category>"),
  ],
});

// Sign and execute
(async () => {
  const result = await suiClient.signAndExecuteTransactionBlock({
    signer: keypair,
    transactionBlock: tx,
    options: { showEffects: true },
  });

  console.log("Transaction Result:", result);
})();

🔎 Real-World Tip

Since enums are custom structured types, you need to encode them using Sui's BCS (Binary Canonical Serialization) format. You can't just pass ["A", "B"] directly — you have to serialize them properly so Move can interpret the values.


📘 Read More

For more on BCS encoding in the Sui SDK: https://docs.sui.io/build/typescript-sdk/advanced-usage#bcs-serialization

And on Move types and function calling: https://docs.sui.io/build/typescript-sdk/dev-guide


0
Comments
.

Do you know the answer?

Please log in and share it.

Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.

420Posts611Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJuly