DEV Community

Cover image for Create an AtomicAssets Template
Ivan Montiel
Ivan Montiel

Posted on • Edited on

Create an AtomicAssets Template

Introduction

We can move onto templates now that we have a Collection and multiple Schemas for our NFT. A template gives us the ability to mint NFTs with some parts of the schema already set. This is useful when we want to guarantee that every NFT has the same set of attributes.

For example, for our Chick Egg NFTs, we will want them all to have the same name, img, and description. With that in mind, we can create a template that we mint the NFTs from. Not only does this save the hassle of making sure we mint every NFT with the same properties, it also enables additional features on AtomicHub. The AtomicHub UI will show users the template their NFT was minted from, the number of their mint, and how many NFTs from that template can exist, have been minted, and how many have been burned. Now users will know exactly where their NFT came from, how rare their NFT is, and how it is performing on the AtomicHub marketplace.

Understanding the createtempl Action

Let’s look at the createtempl method:

createtempl snapshot

Each field is pretty self-explanatory, building off of the collection and schema information that we already have gone over:

  • authorized_creator - in our examples, the author will be the same as the payer of our last examples: waxcourse123. This should be your account name, or an authorized account from the previous collection creation step.
  • collection_name - same as before, babychicknft.
  • schema_name - this is the name of our schema. We will have a babychick and chickegg.
  • transferable - mark whether assets minted with this template will be transferable to other wallets.
  • burnable - mark whether assets minted with this template will be burnable.
  • max_supply - how many NFTs can be minted from this template.
  • immutable_data - this is where we fill in the attributes that will be the same across all NFTs that are minted from this template.

Let’s start with the immutable_data for our templates:

const template = [
    { "key": "name", "value": ["string", "Baby Chick Egg"] },
    { "key": "img", "value": ["image", "QmTAJmKRFUo4SnmKiq6ixM4FuhAQeReHuCBKE1NZZRpkM9"] },
    { "key": "description", "value": ["string", "Baby Chick Egg for hatching"] },
    { "key": "url", "value": ["string", "https://capsulecat.com"] },
    { "key": "socials", "value": ["string", JSON.stringify(socials)] }
];
Enter fullscreen mode Exit fullscreen mode

Here we are defining that the Baby Chick Egg NFT template. When we mint egg NFTs, this is the template they will derive from. All eggs will have the same name, img, description, url, and social information.

Next, let’s look at the immutable_data for Baby Chicks. We are going to mint one of three kinds of Baby Chick NFTs when users hatch their egg – Epic, Rare, and Common chicks.

const templateEpic = [
    { "key": "name", "value": ["string", "Epic Baby Chick"] },
    { "key": "img", "value": ["image", "QmUwqZ64McMgzzP9Hv1qXvEUaubcHQZwAVpdfjKpn9M5vv"] },
    { "key": "description", "value": ["string", "Epic baby chick"] },
    { "key": "rarity", "value": ["string", "Epic"] },
    { "key": "url", "value": ["string", "https://capsulecat.com"] },
    { "key": "socials", "value": ["string", JSON.stringify(socials)] }
];

const templateRare = [
    { "key": "name", "value": ["string", "Rare Baby Chick"] },
    { "key": "img", "value": ["image", "QmdQsG8JNfPSSxNzHE5gwhHmBSJNVYaWLWYwpYpEGX8UJ6"] },
    { "key": "description", "value": ["string", "Rare baby chick"] },
    { "key": "rarity", "value": ["string", "Rare"] },
    { "key": "url", "value": ["string", "https://capsulecat.com"] },
    { "key": "socials", "value": ["string", JSON.stringify(socials)] }
];

const templateCommon = [
    { "key": "name", "value": ["string", "Common Baby Chick"] },
    { "key": "img", "value": ["image", "Qmd2FHnTHw3ernkYegh2xNQK1FFKTd8PwA21ToRhGLvddz"] },
    { "key": "description", "value": ["string", "Common baby chick"] },
    { "key": "rarity", "value": ["string", "Common"] },
    { "key": "url", "value": ["string", "https://capsulecat.com"] },
    { "key": "socials", "value": ["string", JSON.stringify(socials)] }
];
Enter fullscreen mode Exit fullscreen mode

Scripting ChickEgg Templates

Each chick has its own set of attributes to help users identify which type of Baby Chick NFT they have. On AtomicHub, when a user looks up the template their NFT was minted with, they can see the price history of NFTs minted from the same template.

Let’s fill in the rest of the script for creating an egg template:

async function createChickEggTemplates() {
    const author = process.env.WAX_ACCOUNT;

    if (!author) {
        throw new Error("Missing WAX_ACCOUNT");
    }

    try {
        await transact([
            {
                account: "atomicassets",
                name: "createtempl",
                authorization: [
                    {
                        actor: auth,
                        permission: "active",
                    },
                ],
                data: {
                    authorized_creator: auth,
                    collection_name: collectionName('babychicknft'),
                    schema_name: name('chickegg'),

                    transferable: true,
                    burnable: true,
                    max_supply: 100,
                    immutable_data: template
                },
            },
        ])
    } catch (error) {
        console.error(error);
        return false;
    }
}

(async () => {
    const result = await createChickEggTemplates();
    console.log(result);
})();
Enter fullscreen mode Exit fullscreen mode

Scripting BabyChicks Templates

And similarly for the baby chicks, except this time, we are going to execute 3 traces in the same transaction:

async function createBabyChickTemplates() {
    const author = process.env.WAX_ACCOUNT;

    if (!author) {
        throw new Error("Missing WAX_ACCOUNT");
    }

    try {
        await transact([
            {
                account: "atomicassets",
                name: "createtempl",
                authorization: [
                    {
                        actor: auth,
                        permission: "active",
                    },
                ],
                data: {
                    authorized_creator: auth,
                    collection_name: collectionName('babychicknft'),
                    schema_name: name('babychick'),

                    transferable: true,
                    burnable: true,
                    max_supply: 10,
                    immutable_data: templateEpic
                },
            },
            {
                account: "atomicassets",
                name: "createtempl",
                authorization: [
                    {
                        actor: auth,
                        permission: "active",
                    },
                ],
                data: {
                    authorized_creator: auth,
                    collection_name: collectionName('babychicknft'),
                    schema_name: name('babychick'),

                    transferable: true,
                    burnable: true,
                    max_supply: 20,
                    immutable_data: templateRare
                },
            },
            {
                account: "atomicassets",
                name: "createtempl",
                authorization: [
                    {
                        actor: auth,
                        permission: "active",
                    },
                ],
                data: {
                    authorized_creator: auth,
                    collection_name: collectionName('babychicknft'),
                    schema_name: name('babychick'),

                    transferable: true,
                    burnable: true,
                    max_supply: 70,
                    immutable_data: templateCommon
                },
            },
        ])
    } catch (error) {
        console.error(error);
        return false;
    }
}

(async () => {
    const result = await createBabyChickTemplates();
    console.log(result);
})();
Enter fullscreen mode Exit fullscreen mode

Running the Scripts

To run the scripts:

WAX_ACCOUNT=waxcourse123 \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT=<https://testnet.wax.pink.gg> \
  node ./src/030-create-chick-egg-templates.js

WAX_ACCOUNT=waxcourse123 \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT=<https://testnet.wax.pink.gg> \
  node ./src/040-create-baby-chick-templates.js
Enter fullscreen mode Exit fullscreen mode

Example responses:

Example response

Another example response

After running these scripts, we are ready to mint some NFTs!

Next post: Manually Minting an AtomicAssets NFT

E-book

Get this entire WAX tutorial as an e-book on Amazon.

Additional links

Top comments (0)