Object Model

Discover the object model on Sui.

Object-Centric Design

Objects are created and updated by packages (Move structs containing executable code - equivalents to smart contracts on Sui). Typed data is governed by a particular Sui Move module from a Sui Move package. Each object value is a struct with fields containing primitive types (such as integers and addresses), other objects, and non-object structs stored in the Sui storage.

πŸ“˜

Everything is an object on Sui.

Each Sui object has the following metadata:

FieldDescription
IDA unique identifier derived from the digest that created the object and from a counter encoding the number of IDs generated by the transaction.
TypeAn attribute defining the structure and behavior of the object.
VersionAn integer that monotonically increases with every transaction that modifies the object.
Transaction DigestThe digest (hash) of the last transaction that included this object as an output.
OwnerThe field that indicates how this object can be accessed.
DataObjects encapsulate their data, simplifying management and manipulation. The data structure and operations are defined by the object's type.

How objects are created and updated on Sui

Anything on Sui is an object: a coin, a package, an amount of SUI coins, a staking amount, etc. Running a transaction creates new and changes (updates) existing objects. Once an object comes up as a transaction is executed, it is considered created. Later, as more transactions run with this object, it gets updated. Each object has a version showing how many times it has been updated. The version of a newly created object is 0. As this object is updated later, the version incrementally grows with each update.

Transaction Ordering and Parallelization

On most blockchains, transactions are ordered in a block according to the first-in-first-out (FIFO) principle. Simply put, according to the time they were initiated. Then, a series of transactions are added to a block and executed. This process runs consecutively. However, according to the Narwhal and Bullshark Consensus mechanism and the DAG data structure, transactions on Sui are grouped according to the objects associated therewith and executed simultaneously. Below, we draw an analogy to illustrate this point.

πŸ“˜

Analogy

Let's compare transaction ordering to a bus trip.

Traditional blockchains: passengers (transactions) line up (Consensus) to get on a bus (block). Each passenger has their ticket checked (transaction execution) before the bus leaves (adding a block to a blockchain). At the end of the road trip, all passengers get off at a single location (blockchain state update). Only then will the bus be ready to take more passengers.

Sui: passengers (transactions) are grouped according to their destinations (objects). Each group of passengers has their tickets checked in parallel (Consensus), and they're taken by different vehicles (DAG structures) to their destinations simultaneously. Meanwhile, transportation never stops and goes on in a continuous stream.

This transaction execution parallelization immensely improves throughput, cuts latency, and accelerates finality, making transactions near-instant.

πŸ“˜

Transactions with address-owned objects don’t have to go through Consensus.

To learn more about transaction execution, go here.

Object Ownership

On Sui, objects have an owner. Overall, there are four types of objects:

  • Address-Owned Objects

These objects are owned by a concrete account and can be transferred to another account. An example is a transferrable payment amount or a staking amount. A single transaction cannot use objects owned by more than one address.

  • Immutable Objects

An immutable object is a read-only object that can't be mutated, transferred, wrapped, or deleted. Immutable objects have no owner, so anyone can use them. Immutable objects are subject to call operations, usually packages (smart contracts).

  • Shared Objects

Shared objects are accessible to everyone. They are mutable, but they don't have a specific owner. Instead, they can be included in transactions by different parties. They do not require any authorization, but they perform their own authorization logic. Such objects require a full agreement protocol to be used safely. An example of such an object can be a shop or a marketplace.

  • Wrapped Objects

In Move (the language Sui is written on), data structures are organized in layers where complex data structures are wrapped in another data structure. For example, a gaming object (a character) can own another gaming object (an item). In this case, one gaming object will be wrapped in another gaming object. Simply said, a wrapped object is an object owned by another object. Then, the parent object will be a wrapper, while the child object is the wrapped object itself.

Dynamic Fields

Sui provides dynamic fields with arbitrary names (not just identifiers), which are added and removed on the fly (not fixed at publish). These only affect gas when accessed and can store heterogeneous values. Dynamic Fields can store any value. However, an object stored in this field will be considered wrapped and not accessible directly via its ID by external tools (explorers, wallets, etc) accessing storage.

We index and classify numerous Sui objects: coins, packages, NFTs, collections, name service domain names, other unclassified objects.

Gas Objects

On Sui, gas weighs on particular objects as a transaction runs. Respectively, gas objects are objects; the fees are deducted from a gas object specified as an object reference. For more information on gas fees, go here.

Events

Events are the results of running transactions. Events are the primary way to track actions on-chain. Using webhooks, you can subscribe to specific events to keep track of an object of your focus: an account, an NFT, a staking object, etc.

An event object in Sui consists of the following attributes:

FieldDescription
IDJSON object containing the transaction digest ID and event sequence.
packageIdThe object ID of the package that emits the event.
transactionModuleThe module that performs the transaction.
senderThe Sui network address that triggered the event.
typeThe type of event being emitted.
parsedJsonJSON object describing the event.
bscBinary canonical serialization encryption value.
timestampsMsUnix epoch timestamp in milliseconds.

To learn more about objects on Sui, read Sui official docs.