Skip to content

Create a WAX NFT

In this example, we'll write a smart contract that creates a WAX NFT Sticker using the simpleassets smart contract.

WAX NFT Sticker (Example)

Pegatina NFT de WAX

Get Set Up

  1. Use our Docker Quickstart to start a new interactive bash session. From the command line, navigate to the wax directory (or the local directory that you shared with your Docker container).

    cd wax
  2. If you haven't done so already, create a smart contracts directory. For this tutorial, we'll use a folder named mycontracts.

    mkdir mycontracts

    Navigate to this new directory:

    cd mycontracts
  3. From the command line, create a folder named waxnft and navigate to this new directory.

    mkdir waxnft && cd waxnft

Create and Compile Your NFT Smart Contract

  1. In the waxnft folder, create a file named waxnft.cpp and paste the following code into your NFT smart contract:

    #include <eosio/eosio.hpp>
    using namespace eosio;
    CONTRACT waxnft : public eosio::contract{
        using contract::contract;
        ACTION createnft() {
            //assign asset attributes
    	    name author = get_self();
    	    name category = "sticker"_n;
    	    name owner = "waxnftowner1"_n;
    	    std::string idata = R"json({"name": "WAX Developer Hive", "desc" : "WAX Developer Hive Sticker" })json";
    	    std::string mdata = R"json({"color": "black", "img" : "" })json";
    	    bool requireClaim = false;
            //call the simpleassets create action
    		    { author, "active"_n },
    		    std::tuple(author, category, owner, idata, mdata, requireClaim)
    EOSIO_DISPATCH(waxnft, (createnft))

    Save your changes. This contract creates a WAX NFT Sticker with the same author and owner account. Because the requireClaim flag is set to false, your smart contract account is charged the RAM and the asset is instantly assigned to the owner (you).

    • idata includes key/value pairs that can not change.
    • mdata includes key/value pairs that you can update.
  2. From the command line, use WAX-CDT to build your NFT smart contract:

    eosio-cpp -abigen waxnft.cpp -o waxnft.wasm

Your NFT smart contract is now ready to be deployed to the WAX mainnet.