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

Sui Celebrates Second Anniversary with a Tsunami of Growth

With important events like the advent of BTCfi and astronomical user growth, Sui's second year shows enormous promise.

4min read
Sui Foundation

All About DeFi Basics

DeFi users on Sui can engage in various activities, including contributing to liquidity pools, lending, and borrowing.

3min read
Sam Blackshear

The Next Chapter of Brave Frontier Is Built on Sui

The iconic Brave Frontier franchise returns with Brave Frontier Versus, now live on Sui and powered by the next-generation technology stack.

2min read
Sui Foundation

Sui's 17 Biggest Hits of 2024

Sui showed amazing growth and innovation throughout 2024, establishing itself as the most notable blockchain in the industry.

4min read
Sui Foundation

Contribute to the Development of DeepBook

Builders in the community are invited to integrate and test DeepBook, the foundational liquidity layer for Sui.

2min read
Sui Foundation

Figure on the Heels of IPO, Deploys Flagship YLDS Security Token on Sui

SEC-registered security YLDS launches on Sui, unlocking U.S. DeFi liquidity.

4min read
Sui Foundation