Transaction
MicroSui Object-style to represent Sui transactions.
Provides a small OO-like API (struct + function pointers) to interact with Sui Transaction.
Each transaction holds its raw byte data and exposes methods to build or clear its contents to a Sui RPC endpoint over HTTP(S).
Client capabilities: Initialize empty transactions, Create transactions from predefined hex-encoded bytes, Build transactions into raw byte arrays (placeholder), Clear and free transaction memory safely.
IMPORTANT NOTE:
✅ Compatibility & Support:
This class is fully supported and production-stable (as of this documentation release) on:
- ESP32 series — including all existing and future variants within the family
- Desktop platforms — Windows, macOS, Linux, and Unix-based operating systems
⚠️ Full transaction construction using Sui BCS serialization is not yet implemented. For now, transactions are provided manually as raw TxBytes, and the actual construction/serialization is delegated externally.
⚠️ Memory for transaction bytes is dynamically allocated when using SuiTransaction_setPrebuiltTxBytes(). Always call clear() to avoid leaks.
Inspired by the Mysten Labs TypeScript SDK, adapted for embedded C.
File Location
Defined in microsui-lib/src/Transaction.c
Indexs
Constructors
Methods
Constructors
SuiTransaction_init
SuiTransaction_init(): MicroSuiTransaction
Initialize an empty MicroSuiTransaction.
Sets up a transaction with no bytes (data = NULL, length = 0) and assigns method pointers for building and clearing.
Parameters
| Name | Type | Description |
|---|
Returns
MicroSuiTransactionstruct type.
Example usage
MicroSuiTransaction tx = SuiTransaction_init();
// Initiated an empty tx
SuiTransaction_setPrebuiltTxBytes
SuiTransaction_setPrebuiltTxBytes(const char *txBytesString): MicroSuiTransaction
Initialize a MicroSuiTransaction transaction from a prebuilt hex-encoded TxBytes string.
This function is a temporary helper: it assumes the caller already provides the raw transaction bytes (TxBytes) serialized externally, encoded as a hex string. These bytes are then decoded and stored inside the MicroSuiTransaction struct.
The transaction takes ownership of the allocated memory, which will be released when clear is called.
Parameters
| Name | Type | Description |
|---|---|---|
txBytesString | const char * | Null-terminated string containing prebuilt TxBytes (hex-encoded) |
Returns
MicroSuiTransactionstruct type.
Example usage
const char* message_string = "00000200080065cd1d0000000000202e3d52393c9035af";
MicroSuiTransaction tx = SuiTransaction_setPrebuiltTxBytes(message_string);
if (tx.tx_bytes.length > 0)
// Tx created successfully
Methods
build
build(MicroSuiTransaction *self): TransactionBytes
Build, performs BCS serialization operation of the transaction and return the bytes in a new TransactionBytes struct.
⚠️ This method is a placeholder for now, not BCS serialized yet.
Full transaction building with Sui BCS serialization is not yet supported. At this stage, TxBytes are provided manually and construction is delegated externally.
Parameters
| Name | Type | Description |
|---|---|---|
self | MicroSuiTransaction * | Pointer to the MicroSuiTransaction instance |
Returns
TransactionBytesstruct type.
Example usage
We can obtain the tx bytes in the following way:
const char* message_string = "00000200080065cd1d0000000000202e3d52393c9035af";
MicroSuiTransaction tx = SuiTransaction_setPrebuiltTxBytes(message_string);
TransactionBytes built_tx_bytes = tx.build(&tx);
if (built_tx_bytes.length > 0)
// Tx bytes obtained successfully
clear
clear (MicroSuiTransaction *self) : (void)
Clear and free memory of the transaction.
Frees any dynamically allocated memory for transaction bytes, sets the data pointer to NULL, and resets length to zero.
⚠️ VERY IMPORTANT PERFORM THIS AFTER USE THE TRANSACTION OPERATION FOR FREE THE MEMORY.
Parameters
| Name | Type | Description |
|---|---|---|
self | MicroSuiTransaction * | Pointer to the MicroSuiTransaction instance |
Returns
void
Example usage
const char* message_string = "00000200080065cd1d0000000000202e3d52393c9035af";
MicroSuiTransaction tx = SuiTransaction_setPrebuiltTxBytes(message_string);
// ...
tx.clear(&tx);
if (tx.tx_bytes.length == 0)
// Tx data has been freed from memory