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

Response to the Cetus Incident – Onchain Community Vote

Cetus has requested a community driven vote to recover the funds frozen following last week’s hack.

4min read
Sui Foundation

New Sui VM: Bug Bounty Now Open

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

2min read
Sui Foundation

Ika Gives Sui Builders Control Over Other Blockchains

Ika's protocol lets Sui smart contracts interact with assets on other blockchains.

2min read
Sui Foundation

Alibaba Cloud Supports Sui Builders with AI, Hackathons, and Doc Translations

Alibaba Cloud announces an exciting array of new services helping builders create new projects on Sui.

2min read
Sui Foundation

Announcing Enhanced Move VSCode Plugin

Move VSCode plugin now ships with many more cool features.

3min read
Sui Foundation

Gamisodes Animates Inspector Gadget on Sui

Gamisodes leverages Sui's highly performant blockchain technology to breathe new life into Inspector Gadget.

1min read
Sui Foundation