NFT

Prepare modules for production The final stage of development is to get the smart contract module ready for production. This work is mapped into create_nft_getting_production_ready.BSC.

We prepare the production module by:

  1. Add TokenMintingEvent to emit a custom event to track tokens generated from this module.

  2. Enable signature verification and introduce the concept of proof challenges to prevent bot spam.

  3. Include unit tests to ensure our code works as expected.

Create NFT

  1. Run the following command to attempt to mint an NFT, including your <resource-account-address> (failure expected):

ait move run --function-id <resource-account-address>:
:create_nft_with_resource_and_admin_accounts:
:mint_event_ticket --profile nft-receiver

{
  "Result": {
    "create_hash": "0x82660973b1a94e620c8638f9a157b0b46c02dcfbb0c9261a34ed4d2391540787",
    "gas_used": 6691,
    "gas_unit_price": 100,
    "sender": "aaf005db7b6dacb1db4637e8017e68e689a40797fe8fd3897cee0880897788fb",
    "sequence_number": 0,
    "success": true,
    "timestamp_us": 1667434233137811,
    "version": 27685944,
    "vm_status": "Executed successfully"
  }
}
*/

Mint the NFT

  1. Mint the NFT by calling the mint_nft function and an existing contract using the Aits CLI:

aits move run --function-id 8cdf69c8c93fee36ed83f8882908060c1335ed39a827c08dbb506b46237e88fb::minting::mint_nft --profile nft-receiver

{ "Result": { "transaction_hash": "0x6e022532fb8d802324829d5ec85fd32c05a58a6f826751f63cdbf9bf313ff991",

"gas_used": 3944,

"gas_unit_price": 150,

"sender": "b9d394a7bc582a54e8610d6a7b973f62c8d9595c54c35cdbb95965aa8e5cd111",

"sequence_number": 0,

"success": true,

"timestamp_us": 1670969779029341,

"version": 385901038,

"vm_status": "Executed successfully" }

}

*/

NFT Airdrops

Using the NFT mint example replace the mint function with an airdrop function as below.

public entry fun airdrop(whitelist: vector) acquires ModuleData {

let module_data = borrow_global_mut(@mint_nft);

let count = vector::length(&whitelists);

let resource_signer = account::create_signer_with_capability(&module_data.signer_cap);

let token_id = token::mint_token(&resource_signer, module_data.token_data_id, count);

let i: u64 = 0;

let i: u64 = 0;

let receiver = vector::pop_back(&mut whitelist);

token_transfers::offer(&resource_signer, receiver, token_id, 1);

i = i + 1;

};

}

Refresh the page to view the latest documents

Last updated