5. Create your own Move NFT
This tutorial covers a guide to mint my own NFT and collection using 0x1::simple_nft module. Also, let's understand the concept of Object by transfering NFTs.
Step 1: Create Collection
To create NFTs, a collection must be created first. Let's use 0x1::simple_nft::create_collection to create a new collection.
public entry fun create_collection(
creator: &signer,
description: String,
max_supply: Option<u64>,
name: String,
uri: String,
mutable_description: bool,
mutable_royalty: bool,
mutable_uri: bool,
mutable_nft_description: bool,
mutable_nft_properties: bool,
mutable_nft_uri: bool,
royalty: Decimal128,
)> initiad tx move execute 0x1 simple_nft create_collection \
--args "string:description option<u64>:100 string:my_collection string: bool:true bool:true bool:true bool:true bool:true bool:true decimal128:0.05" \
--from [key-name] \
--gas auto --gas-adjustment 1.5 --gas-prices 0.15uinit \
--node [rpc-url]:[rpc-port] --chain-id [chain-id]import {
bcs,
LCDClient,
MnemonicKey,
MsgExecute,
Wallet,
} from '@initia/initia.js';
async function createCollection() {
const lcd = new LCDClient('[rest-url]', {
gasPrices: '0.15uinit',
gasAdjustment: '1.5',
});
const key = new MnemonicKey({
mnemonic: 'beauty sniff protect ...',
});
const wallet = new Wallet(lcd, key);
const msgs = [
new MsgExecute(
key.accAddress,
'0x1',
'simple_nft',
'create_collection',
[],
[
bcs.string().serialize('description').toBase64(), // collection description
bcs.option(bcs.u64()).serialize(100).toBase64(), // max supply
bcs.string().serialize('my_collection').toBase64(), // collection name
bcs.string().serialize('').toBase64(), // collection uri
bcs.bool().serialize(true).toBase64(), // mutable collection description
bcs.bool().serialize(true).toBase64(), // mutable collection royalty
bcs.bool().serialize(true).toBase64(), // mutable collection uri
bcs.bool().serialize(true).toBase64(), // mutable nft description
bcs.bool().serialize(true).toBase64(), // mutable nft properties
bcs.bool().serialize(true).toBase64(), // mutable nft uri
bcs.decimal128().serialize('0.05').toBase64(), // royalty
]
),
];
// sign tx
const signedTx = await wallet.createAndSignTx({ msgs });
// send(broadcast) tx
lcd.tx.broadcastSync(signedTx).then(res => console.log(res));
// {
// height: 0,
// txhash: '0F2B255EE75FBA407267BB57A6FF3E3349522DA6DBB31C0356DB588CC3933F37',
// raw_log: '[]'
// }
}
createCollection();
Step 2: Mint NFT
Call 0x1::simple_nft::mint function to mint NFTs to myself.
Check minted NFTs
There are multiple ways to check NFTs, but the below API can be used to check the NFTs minted to myself.
Get collection list owned by me: https://stone-api.initia.tech/v1/nfts/collections?account=[addr]
Get NFT list owned by me: https://stone-api.initia.tech/v1/nfts/tokens?account={my_address}&collection={collection_address}
Transfer NFT
A single NFT is a single object, and transfer can be done by 0x1::object::transfer_call.
Last updated