On the Sui blockchain, every asset is treated as an object. A key characteristic of Sui is that each object is unique, non-interchangeable, and has clearly defined ownership—effectively making every object a non-fungible token (NFT). This means that from a technical standpoint, even basic data structures can serve as NFTs when deployed on Sui.
This article explains how to create and manage NFTs on the Sui network using a sample smart contract, providing both technical guidance and practical context.
Understanding NFTs on Sui
Non-fungible tokens represent ownership of unique digital or physical items. On Sui, the concept of an NFT is native to the platform’s design. Each object in Sui has a unique identifier and ownership metadata, making it inherently non-fungible.
Thanks to Sui’s object-oriented architecture, developers can easily define custom NFT types with specific properties and behaviors. These can represent anything from digital art and collectibles to real-world asset certificates.
Sample NFT Contract Breakdown
Here’s a practical example of an NFT smart contract written in Sui Move:
module examples::devnet_nft {
use sui::url::{Self, Url};
use std::string;
use sui::object::{Self, ID, UID};
use sui::event;
use sui::transfer;
use sui::tx_context::{Self, TxContext};
/// An example NFT that can be minted by anybody
struct DevNetNFT has key, store {
id: UID,
/// Name for the token
name: string::String,
/// Description of the token
description: string::String,
/// URL for the token
url: Url,
// TODO: allow custom attributes
}
// ===== Events =====
struct NFTMinted has copy, drop {
// The Object ID of the NFT
object_id: ID,
// The creator of the NFT
creator: address,
// The name of the NFT
name: string::String,
}
// ===== Public view functions =====
/// Get the NFT's `name`
public fun name(nft: &DevNetNFT): &string::String {
&nft.name
}
/// Get the NFT's `description`
public fun description(nft: &DevNetNFT): &string::String {
&nft.description
}
/// Get the NFT's `url`
public fun url(nft: &DevNetNFT): &Url {
&nft.url
}
// ===== Entrypoints =====
/// Create a new devnet_nft
public fun mint_to_sender(
name: vector<u8>,
description: vector<u8>,
url: vector<u8>,
ctx: &mut TxContext
) {
let sender = tx_context::sender(ctx);
let nft = DevNetNFT {
id: object::new(ctx),
name: string::utf8(name),
description: string::utf8(description),
url: url::new_unsafe_from_bytes(url)
};
event::emit(NFTMinted {
object_id: object::id(&nft),
creator: sender,
name: nft.name,
});
transfer::public_transfer(nft, sender);
}
/// Transfer `nft` to `recipient`
public fun transfer(
nft: DevNetNFT, recipient: address, _: &mut TxContext
) {
transfer::public_transfer(nft, recipient)
}
/// Update the `description` of `nft` to `new_description`
public fun update_description(
nft: &mut DevNetNFT,
new_description: vector<u8>,
_: &mut TxContext
) {
nft.description = string::utf8(new_description)
}
/// Permanently delete `nft`
public fun burn(nft: DevNetNFT, _: &mut TxContext) {
let DevNetNFT { id, name: _, description: _, url: _ } = nft;
object::delete(id)
}
}Core Components of the NFT Contract
- Struct Definition: The
DevNetNFTstruct defines the NFT’s properties: unique ID, name, description, and a URL—typically pointing to metadata or media. - Event Emission: The contract emits an
NFTMintedevent upon creation, logging key details like object ID and creator. - Public Functions: These include view functions to read NFT attributes and entry functions for minting, transferring, updating, and burning tokens.
Key Functions in the NFT Module
Minting an NFT
The mint_to_sender function allows users to create a new NFT. It accepts:
- Name and description as byte vectors
- A URL pointing to external metadata
- A transaction context for identifying the sender
The function creates the NFT object, emits a minting event, and transfers the token to the sender.
Transferring Ownership
The transfer function enables the current owner to send the NFT to another address. This uses Sui’s built-in transfer mechanism, which securely updates ownership.
Updating Metadata
The update_description function allows modifying the NFT’s description. This demonstrates how mutable metadata can be implemented—though many NFTs prefer immutability for authenticity.
Burning an NFT
The burn function permanently destroys the NFT by deallocating its object storage. This is useful for removing tokens from circulation.
Use Cases for Sui NFTs
Sui’s NFT infrastructure supports various applications:
- Digital collectibles and art
- In-game items and assets
- Identity verification and credentials
- Tokenized real-world assets
- Membership passes and tickets
The platform’s high throughput and low transaction costs make it suitable for NFT-based applications at scale.
👉 Explore more NFT development strategies
Frequently Asked Questions
What makes Sui suitable for NFT development?
Sui’s object-centric model treats all assets as unique objects with built-in ownership tracking. This aligns perfectly with the non-fungible nature of NFTs, simplifying development and improving performance.
Can I update NFT metadata after minting on Sui?
Yes, the sample contract includes an update_description function that allows modifying metadata. However, whether NFTs are mutable or immutable is a design choice—developers can implement either based on their use case.
How are NFT transfers handled on Sui?
Sui uses a secure, built-in transfer mechanism that updates ownership records on-chain. The transfer function in the sample contract leverages this system to send NFTs between addresses.
What is the cost of minting an NFT on Sui?
Minting costs on Sui are generally lower than on many other blockchains due to its efficient consensus mechanism and storage model. Exact costs depend on network congestion and transaction complexity.
Can I create NFTs with custom attributes?
Absolutely. The sample contract includes a TODO comment suggesting the addition of custom attributes. Developers can extend the DevNetNFT struct to include any required properties.
How do I view my minted NFTs?
NFTs minted on Sui can be viewed in compatible wallets that support the Sui standard. These wallets display the NFT’s metadata, including name, description, and associated media.
Conclusion
Creating NFTs on Sui is straightforward thanks to the platform’s object-oriented architecture. The provided sample contract demonstrates core functionality including minting, transferring, updating, and burning tokens. Developers can extend this foundation to build sophisticated NFT applications with custom logic and metadata structures.
Sui’s performance characteristics and developer-friendly environment make it an attractive platform for NFT projects ranging from digital art collections to complex gaming ecosystems.