In the third video of Encode Club’s Sui series, we review the nature of objects on Sui, and walk through the steps necessary to create a non-fungible token (NFT).

The Sui Foundation partnered with Encode Club to offer a series of six developer-focused videos. This series will range from the basics of Sui to tutorials about building smart contracts and working with objects in Sui.

Learning Highlights

Sui’s data model makes creating objects a fundamental part of coding on the network. Here we offer code snippets showing the four different object models, the components of a unique identifier, and how to create an NFT.

Object Review

Briefly summarizing what we went over in the previous session, objects in Sui are the most basic unit of storage. Objects fall into one of four categories:

Address-owned object

struct ObjectA has key { id: UID }

public entry fun create_object_owned_by_an_address(ctx: &mut TxContext) {
transfer::transfer({
ObjectA { id: object::new(ctx) }
}, tx_context::sender(ctx))
}

Object-owned object

struct ObjectB has key, store { id: UID }

public entry fun create_object_owned_by_an_object(parent: &mut ObjectA, ctx: &mut TxContext) {
let child = ObjectB { id: object::new(ctx) };
ofield::add(&mut parent.id, b"child", child);
}

Shared object

struct ObjectC has key { id: UID }

public entry fun create_shared_object(ctx: &mut TxContext) {
transfer::share_object(ObjectC { id: object::new(ctx) })
}

Immutable object

struct ObjectD has key { id: UID }

public entry fun create_immutable_object(ctx: &mut TxContext) {
transfer::freeze_object(ObjectD { id: object::new(ctx) })
}

Objects and NFTs

Technically, there are no differences between objects and NFTs on Sui. Let’s examine the Sui standard library’s definition of unique identifier (UID) from option.move using the code snippet below.

/// Globally unique IDs that define an object's ID in storage. Any Sui object, that is a struct
/// with the `key` ability, must have `id: UID` as its first field.
/// These are globally unique in the sense that no two values of type `UID` are ever equal, in
/// other words for any two values `id1: UID` and `id2: UID`, `id1` != `id2`.
/// This is a privileged type that can only be derived from a `TxContext`.
/// `UID` doesn't have the `drop` ability, so deleting a `UID` requires a call to `delete`.
struct UID has store {
id: ID,
}


Because Sui generates a globally unique ID every time a new object is created, no two objects will ever be truly fungible, even if the rest of their fields are identical.

Creating an NFT in Sui

Due to Sui’s object-centric approach, creating an NFT is relatively simple, as shown in the code snippet below.

struct NFT has key, store {
id: UID,
name: String,
description: String,
url: Url,
// ... Additional attributes for various use cases (i.e. game, social profile, etc.)
}


However, the above displays a rudimentary example. Sui’s unique programming model allows practically limitless use cases. Anyone interested in contributing ideas on NFT standards or how they could be supercharged to the next level should visit our official Sui Developers forum!

Watch the Whole Series

  1. What's Sui?
  2. Smart Contracts
  3. Creating Objects and NFTs
  4. Dynamic Fields and Collections
  5. RPG Building Basics
  6. Deploy a Game to the Blockchain
Author

Sam Blackshear

Co-Founder, CTO, Mysten Labs, Creator of Move Language

CTO of Mysten Labs and inventor of Move language. Former Principal Engineer at Meta.

Read more like this

New Sui VM: Bug Bounty Now Open

Sui's execution layer is getting its most significant improvement since launch

2min read
Sui Foundation

Building the Capy Prototype on Sui

Sui Capys, Mysten Labs’ new prototype, serves as a developer preview and demonstrates key capabilities of the Sui ecosystem.

8min read
Sui Foundation

Open Market Group’s Real-World Asset Opportunities Land on Sui

Open Market Group unlocks secure access to offchain yield on Sui.

1min read
Sui Foundation

Sam Blackshear on the Origins of Move

Mysten Labs CTO and inventor of the Move programming language discusses the motivation behind developing it.

1min read
Sam Blackshear

Ant Digital Technologies Launches ESG-Focused RWA Project on Sui

Ant Digital will tokenize assets that comport with environmental, social, and governance standards.

2min read
Sui Foundation

Sui Appoints Christian Thompson to Lead Its Next Growth Phase

Thompson chosen as Managing Director of the Sui Foundation to further its mission of growth and adoption.

2min read
Sui Foundation