module examples::testnet_nft {
use std::string;
use sui::event;
use sui::url::{Self, Url};
/// An example NFT that can be minted by anybody
public struct TestnetNFT has key, store {
id: UID,
name: string::String,
description: string::String,
url: Url,
}
/// Event emitted when NFT is minted
public struct NFTMinted has copy, drop {
object_id: ID,
creator: address,
name: string::String,
}
/// Get the NFT's name
public fun name(nft: &TestnetNFT): &string::String {
&nft.name
}
/// Get the NFT's description
public fun description(nft: &TestnetNFT): &string::String {
&nft.description
}
/// Get the NFT's URL
public fun url(nft: &TestnetNFT): &Url {
&nft.url
}
/// Mint an NFT and transfer to sender
public fun mint_to_sender(
name: vector<u8>,
description: vector<u8>,
url: vector<u8>,
ctx: &mut TxContext,
) {
let sender = ctx.sender();
let nft = TestnetNFT {
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: TestnetNFT,
recipient: address,
_: &mut TxContext
) {
transfer::public_transfer(nft, recipient)
}
/// Update NFT description
public fun update_description(
nft: &mut TestnetNFT,
new_description: vector<u8>,
_: &mut TxContext,
) {
nft.description = string::utf8(new_description)
}
/// Burn an NFT
public fun burn(nft: TestnetNFT, _: &mut TxContext) {
let TestnetNFT { id, name: _, description: _, url: _ } = nft;
id.delete()
}
}