Module 0x107a::nft
- Struct
NFT
- Resource
Nft
- Function
init
- Function
destroy
- Function
legacy_sender
- Function
metadata
- Function
tag
- Function
immutable_issuer
- Function
immutable_metadata
- Function
id
use 0x107a::irc27;
use 0x1::option;
use 0x1::string;
use 0x2::display;
use 0x2::object;
use 0x2::package;
use 0x2::transfer;
use 0x2::tx_context;
Struct NFT
One Time Witness.
struct NFT has drop
Fields
dummy_field: bool
Resource Nft
The Stardust NFT representation.
struct Nft has store, key
Fields
id: object::UID
The Nft's ID is nested from Stardust.
legacy_sender: option::Option<address>
The sender feature holds the last sender address assigned before the migration and is not supported by the protocol after it.
metadata: option::Option<vector<u8>>
The metadata feature.
tag: option::Option<vector<u8>>
The tag feature.
immutable_issuer: option::Option<address>
The immutable issuer feature.
immutable_metadata: irc27::Irc27Metadata
The immutable metadata feature.
Function init
The Nft
module initializer.
fun init(otw: nft::NFT, ctx: &mut tx_context::TxContext)
Implementation
fun init(otw: NFT, ctx: &mut TxContext) {
// Claim the module publisher.
let publisher = package::claim(otw, ctx);
// Build a Display
object.
let keys = vector[
// The Iota standard fields.
string::utf8(b"name"),
string::utf8(b"image_url"),
string::utf8(b"description"),
string::utf8(b"creator"),
// The extra IRC27-nested fields.
string::utf8(b"version"),
string::utf8(b"media_type"),
string::utf8(b"collection_name"),
// The issuer of the NFT. Equivalent to IRC-27 collectionId
.
string::utf8(b"immutable_issuer"),
];
let values = vector[
// The Iota standard fields.
string::utf8(b"{immutable_metadata.name}"),
string::utf8(b"{immutable_metadata.uri}"),
string::utf8(b"{immutable_metadata.description}"),
string::utf8(b"{immutable_metadata.issuer_name}"),
// The extra IRC27-nested fields.
string::utf8(b"{immutable_metadata.version}"),
string::utf8(b"{immutable_metadata.media_type}"),
string::utf8(b"{immutable_metadata.collection_name}"),
// The issuer of the NFT. Equivalent to IRC-27 collectionId
.
string::utf8(b"{immutable_issuer}"),
];
let mut display = display::new_with_fields<Nft>(
&publisher,
keys,
values,
ctx
);
// Commit the first version of Display
to apply changes.
display.update_version();
// Burn the publisher object.
package::burn_publisher(publisher);
// Freeze the display object.
iota::transfer::public_freeze_object(display);
}
Function destroy
Permanently destroy an Nft
object.
Implementation
public fun destroy(nft: Nft) {
let Nft {
id,
legacy_sender: _,
metadata: _,
tag: _,
immutable_issuer: _,
immutable_metadata,
} = nft;
irc27::destroy(immutable_metadata);
object::delete(id);
}
Function legacy_sender
Get the Nft's legacy_sender
.
public fun legacy_sender(nft: &nft::Nft): &option::Option<address>
Implementation
public fun legacy_sender(nft: &Nft): &Option<address> {
&nft.legacy_sender
}
Function metadata
Get the Nft's metadata
.
public fun metadata(nft: &nft::Nft): &option::Option<vector<u8>>
Function tag
Get the Nft's tag
.
public fun tag(nft: &nft::Nft): &option::Option<vector<u8>>
Function immutable_issuer
Get the Nft's immutable_sender
.
public fun immutable_issuer(nft: &nft::Nft): &option::Option<address>
Implementation
public fun immutable_issuer(nft: &Nft): &Option<address> {
&nft.immutable_issuer
}
Function immutable_metadata
Get the Nft's immutable_metadata
.
public fun immutable_metadata(nft: &nft::Nft): &irc27::Irc27Metadata
Implementation
public fun immutable_metadata(nft: &Nft): &Irc27Metadata {
&nft.immutable_metadata
}
Function id
Get the Nft's id.
public(friend) fun id(self: &mut nft::Nft): &mut object::UID