How would you create a collection in Sui with a name and URL and then mint NFTs under that collection with a unique name and URL? What is the standard syntax-wise?
Please check out this page:
docs [dot] sui [ dot] io/guides/developer/nft
From this link I know how to name each NFT…but it is not clear how to set the name of the collection for all the minted NFTs. What I found out from the explorer is that the collection name is set to the name of the first NFT that was minted. That’s not what I want and I want to name the collection.
A good way of doing what you are trying to do is by taking advantage of the Display capabilities.
Assuming you have an NFT definition like this:
public struct NFT has key, store {
id: UID,
name: String,
collection: String,
number: u64
}
Your display could show the name like this:
{
"name": "{collection}#{number} {name}"
"img_url": ....
}
So if you create the display in move for the name
key you should have a value like
{collection} <whatever else you want>
{collection} will take the collection
field value of the NFT and replace it in the Display name.
So with my proposal from this NFT:
NFT: {
id: 0xaaa,
name: Harrison,
number: 1000
collection: AwesomePpl
}
The display on explorer or wallets will show: AwesomePpl#1000 Harrison
.
I hope this is what you are looking for.
@alex_devrel Thanks! That actually worked. Maybe add this part on the documentation as well.
@alex_devrel one small follow-up… how can I give each NFT a unique name without including the collection name…but I would still like to keep the NFTs under the same collection name.
How can I achieve this by utilizing the display standard?
The display works something like the string literals in javascript if you are familiar, for example if you have the following:
const name = "Nam3";
const collection = "Coll3ction";
console.log(`The name is ${name} and the collection is ${collection});
It will print out The name is Nam3 and the collection is Coll3ction
, right?
So for Display the explorers and wallets will show for the NFT name whatever value you have set for the name
key.
For example if you have an NFT like this:
public struct NFT has key, store{
id: UID,
collection: String,
unique_name: String,
img_url: String
}
and then you define your Display like this:
let keys: vector<String> = vector[string::utf8(b"name"), string::utf8(b"image_url")];
let values: vector<String> = vector[
string::utf8("My name is {unique_name} and my collection is {collection}"),
string::utf8("{img_url}")
];
let display = display::new_with_fields<NFT> (&publisher, &keys, &values, ctx);
Then any wallet or explorer and other Display compatible apps, when you open an NFT they will get the unique_name
field and collection
field from NFT, they will substitute them inside the string "My name is {unique_name} and my collection is {collection}"
and show the result as the name of the NFT.
So now it is possible to show NFT names on apps and also it is possible to dynamically update some part of the string according to the current NFT being showed.
So taking advantage of this feature you should be able to control what appears when someone opens your NFT in an explorer.
Hello,
As per my knowledge, To create a collection in Sui:
To create a collection in Sui:
To mint NFTs within that collection:
let nft = sui::mint_nft(&collection, "UniqueNFTName", "http://nft-url.com");
This creates a collection and mints NFTs with unique names and URLs.
Thanks in advance!
Respected community member
@alex_devrel So what I want to do is to have a unique collection name and set a unique NFT name for each NFT. For example, set the collection name to Animals
and each NFT name would be tiger
, lion
, rabbit
etc.
I see two ways to set collection:
- The collection name should not be included in the NFT name.
fun init(otw: BIRDNFT, ctx: &mut TxContext) {
let publisher = package::claim(otw, ctx);
let keys = vector[
utf8(b"name"),
utf8(b"image_url"),
utf8(b"description"),
];
let values = vector[
utf8(b"{name}"),
utf8(b"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTd-p8dBZvujdcP3R_snd8LH5z9nmYybs12zA&s"),
utf8(b"Collection of Red Birds!"),
];
let mut display = display::new_with_fields<NFT>(
&publisher, keys, values, ctx
);
display::update_version(&mut display);
transfer::public_transfer(publisher, tx_context::sender(ctx));
transfer::public_transfer(display, tx_context::sender(ctx));
transfer::share_object(NumCount{
id: object::new(ctx),
current_number: 0
});
}
public entry fun mint_nft(name: String, num_count: &mut NumCount, ctx: &mut TxContext) {
let current_number = &mut num_count.current_number;
*current_number = *current_number + 1;
let new_bird_nft = NFT {
id: object::new(ctx),
name,
collection: utf8(b"RedBirds"),
number: *current_number
};
transfer::public_transfer(new_bird_nft, tx_context::sender(ctx));
}
In this case the collection name is set to the name of the first NFT I minted. Collection link:
https:// suiscan.xyz/mainnet/collection/0x33dcf5ddc99d431e6e74087d1c180e1b9b652b6249910e98cd036ec1c89c27ea::birdnft::NFT/items
- Setting collection name in the:
fun init(otw: BIRDNFT, ctx: &mut TxContext) {
let publisher = package::claim(otw, ctx);
let keys = vector[
utf8(b"name"),
utf8(b"image_url"),
utf8(b"description"),
];
let values = vector[
utf8(b"{collection} #{number} {name}"),
utf8(b"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTthlzS2gC2JL_LjqtShVQ3icv73-EAqXVHXw&s"),
utf8(b"Collection of Black Birds!"),
];
let mut display = display::new_with_fields<NFT>(
&publisher, keys, values, ctx
);
display::update_version(&mut display);
transfer::public_transfer(publisher, tx_context::sender(ctx));
transfer::public_transfer(display, tx_context::sender(ctx));
transfer::share_object(NumCount{
id: object::new(ctx),
current_number: 0
});
}
public entry fun mint_nft(name: String, num_count: &mut NumCount, ctx: &mut TxContext) {
let current_number = &mut num_count.current_number;
*current_number = *current_number + 1;
let new_bird_nft = NFT {
id: object::new(ctx),
name,
collection: utf8(b"BlackBirds"),
number: *current_number
};
transfer::public_transfer(new_bird_nft, tx_context::sender(ctx));
In this case, the collection name gets a unique name but each NFT has to have the NFT name included in it. Collection link:
https:// suiscan.xyz/mainnet/collection/0xc69d42af3b2f487580255e5911379a57e6eb248d17a9c9037ee7528be0fb472b::birdnft::NFT/items
So I want something in the middle: Unique collection name and unique NFT names without including the collection name. How can I achieve that?