Creating Move NFT
Overview
Creating and managing your own NFTs using the 0x1::simple_nft module involves several steps, including creating a collection, minting NFTs, checking minted NFTs, and transferring NFTs. This tutorial will guide you through these steps, focusing on syntax and essential commands to interact with the blockchain.
Tutorial
Step 1: Create Collection
To mint NFTs, you first need to create a collection. You'll use the 0x1::simple_nft::create_collection function for this purpose. This function requires numerous parameters, including descriptions, maximum supply, collection name, and various flags to allow mutability in your collection's properties.
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
After creating a collection, you can mint NFTs within this collection using the 0x1::simple_nft::mint function. This function also requires various parameters, including the collection name, a description of the NFT, the token ID, and an optional recipient address.
public entry fun mint(
    creator: &signer,
    collection: String,
    description: String,
    token_id: String,
    uri: String,
    property_keys: vector<String>,
    property_types: vector<String>,
    property_values: vector<vector<u8>>,
    to: Option<address>,
)> initiad tx move execute 0x1 simple_nft mint \
  --args "string:my_collection string:nft_description string:nft_1 string: vector<string>: vector<string>: vector<vector<u8>>: option<address>:[receiver-addr]" \
  --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 mintNft() {
  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',
      'mint',
      [],
      [
        bcs.string().serialize('my_collection').toBase64(), // collection name
        bcs.string().serialize('nft_description').toBase64(), // nft description
        bcs.string().serialize('nft_1').toBase64(), // nft token id
        bcs.string().serialize('').toBase64(), // nft uri
        bcs.vector(bcs.string()).serialize([]).toBase64(), // property keys
        bcs.vector(bcs.string()).serialize([]).toBase64(), // property types
        bcs.vector(bcs.vector(bcs.u8())).serialize([]).toBase64(), // property values
        bcs.option(bcs.address()).serialize(key.accAddress).toBase64(), // to, if null mint to creator
      ]
    ),
  ];
  // sign tx
  const signedTx = await wallet.createAndSignTx({ msgs });
  // send(broadcast) tx
  lcd.tx.broadcastSync(signedTx).then(res => console.log(res));
  // {
  //   height: 0,
  //   txhash: '162AA29DE237BD060EFEFFA862DBD07ECD1C562EBFDD965AD6C34DF856B53DC2',
  //   raw_log: '[]'
  // }
}
mintNft();
Step 3: Check Minted NFTs
You can check the NFTs you've minted by accessing specific APIs. For checking collections and tokens owned by a specific address, use the following endpoints, replacing [addr] and [collection_address] with actual values:
- Collections owned by a specific address: https://api.initiation-1.initia.xyz/indexer/nft/v1/collections/by_account/[addr] 
- NFTs owned by a specific address: https://api.initiation-1.initia.xyz/indexer/nft/v1/tokens/by_account/[addr] 
Step 4: Transfer NFT
To transfer an NFT, use the 0x1::object::transfer_call function. This function allows transferring a single NFT from one account to another.
public entry fun transfer_call(
    owner: &signer,
    object: address,
    to: address,
)> initiad tx move execute 0x1 object transfer_call \                                                                   
  --args "address:[object-addr] address:[receiver-addr]" \                                                  
  --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 transferNft() {
  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',
      'object',
      'transfer_call',
      [],
      [
        bcs
          .address()
          .serialize(
            '0x6bb8659546a0c220a6f47f97042b79262afeecc87b59b9db1d60869fafe965b3'
          )
          .toBase64(), // object address (nft address)
        bcs
          .address()
          .serialize('init10v3kg8hfvsj6tklfj5aam9ya5lmvtl9snqsawg')
          .toBase64(), // receiver address
      ]
    ),
  ];
  // sign tx
  const signedTx = await wallet.createAndSignTx({ msgs });
  // send(broadcast) tx
  lcd.tx.broadcastSync(signedTx).then(res => console.log(res));
  // {
  //   height: 0,
  //   txhash: '6C34E97A9AECFC89765AC63225EB731BCED34C5B05281B17A4D28B8730CCFC55',
  //   raw_log: '[]'
  // }
}
transferNft();
Last updated