Move.

Post

Share your knowledge.

Satoshi .
Sep 01, 2025
Expert Q&A

Using events for analytics in Sui Move

How do I properly emit events in Sui Move for off-chain indexing? Are there specific patterns or traits I should follow for structured logging?

  • Move CLI
  • Move
  • Smart Contract
1
2
Share
Comments
.

Answers

2
NakaMoto. SUI.
Sep 1 2025, 13:41

How to Emit Events in Sui Move

  1. Define an Event Structure

Create a struct that represents the event payload.

Add the drop ability because events are not stored permanently on-chain; they are emitted and discarded.

module my_project::example {

use sui::event;

/// Define the event structure
struct PurchaseEvent has drop {
    buyer: address,
    item_id: u64,
    price: u64,
}

public fun emit_purchase_event(buyer: address, item_id: u64, price: u64) {
    let event = PurchaseEvent { buyer, item_id, price };
    event::emit(event);
}

}

event::emit is the standard function for emitting events.

Best Practices for Structured Logging

  1. Use Strongly Typed Structs

Avoid raw strings or arbitrary maps.

Define fields explicitly for predictable indexing.

  1. Keep Events Lightweight

Emit only essential information (IDs, addresses, numeric values).

Do not include large data like metadata or JSON.

  1. Emit Events at Critical Points

Actions like mint, transfer, burn, or state transitions (e.g., auction closed, order executed).

  1. Version Your Event Structures

If you upgrade a module, consider adding version suffix (e.g., PurchaseEventV2) for backward compatibility.

  1. Ensure Deterministic Ordering

Events should reflect the order of operations for easy reconstruction of history off-chain.


✅ How to Query Events Off-Chain

Use Sui’s RPC or Indexer API:

sui_getEvents or GraphQL endpoints can query by:

Event type (module + struct name)

Sender address

Transaction digest

Example:

sui_getEvents(filter: { MoveEventType: "0x2::my_project::PurchaseEvent" })

Tools like Sui Indexer, Kafka event streams, or custom indexer can subscribe to these events for analytics.

Security Consideration

Do not rely on events for on-chain logic because they are not part of state.

Only use events for off-chain analytics, notifications, and dashboards.

0
Comments
.

Do you know the answer?

Please log in and share it.

Move is an executable bytecode language used to implement custom transactions and smart contracts.

249Posts553Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

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

Reward CampaignSeptember