Introduction
There are a few ways you can mint NFTs using AtomicAssets. In this tutorial we will focus on minting NFTs via a Smart Contract. However, you can write a script to mint NFTs using the same functionality we already defined in the last few sections. This is extremely useful for minting and air-dropping NFTs to users. For example, if you are having a promotion for users who joined your Discord server early, you can mint them the first set of NFTs and airdrop them for free.
Understanding the mintasset Action
Let’s look at the mintasset
method of the AtomicAssets Smart Contract:
Let’s look at each parameter closely:
-
authorized_minter
- which account is minting the asset. A common practice in Smart Contract methods is to take aname
as a parameter and verify that the caller has auth to act on behalf of thatname
. -
collection_name
- the collection we are minting from, in our case it isbabychicknft
. -
schema_name
- the schema for the NFT we are minting. If we are minting an egg, itschickegg
. -
template_id
- our eggs have a template, but the id will be different for each contract deployment. In our case it isTODO
. -
immutable_data
- there are additional fields we will need to set in addition to those in our template. -
mutable_data
- we didn’t define any mutable_data, but we can set data for our NFT when we mint it that can be changed later. While typically an NFT is thought to be completely immutable, AtomicAssets has a specific section in them that can be updated. We will go over this more in later sections. -
tokens_to_back
- we won’t be covering this in these tutorials, but you can back an NFT with other NFTs.
Scripting an NFT Mint
To test that we have set up our collection correctly, let’s mint a single egg NFT!
import { transact } from "./utilities/transact";
import { name, collectionName } from "./utilities/name";
const nftData = [
{ "key": "created_at", "value": ["uint64", Date.now()] },
];
async function mintChickEgg() {
const author = process.env.WAX_ACCOUNT;
if (!author) {
throw new Error("Missing WAX_ACCOUNT");
}
const templateId = process.env.TEMPLATE_ID;
if (!templateId) {
throw new Error("Missing TEMPLATE_ID");
}
try {
await transact([
{
account: "atomicassets",
name: "mintasset",
authorization: [
{
actor: author,
permission: "active",
},
],
data: {
authorized_minter: author,
collection_name: collectionName('babychicknft'),
schema_name: name('chickegg'),
new_asset_owner: author,
template_id: templateId,
immutable_data: nftData,
mutable_data: [],
tokens_to_back: [],
},
},
])
} catch (error) {
console.error(error);
return false;
}
}
(async () => {
const result = await mintChickEgg();
console.log(result);
})();
Since our template defines most of the Chick Egg schema, we only need to provide the created_at
field. We will need to run this script with an additional environment variable though. The TEMPLATE_ID field is 62936
which is the ID from our template create action:
WAX_ACCOUNT=waxcourse123 \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT="https://testnet.wax.pink.gg" \
TEMPLATE_ID="629366" \
node ./src/050-mint-chick-egg.js
Example response:
Now that we have manually minted an NFT, let’s look at how we can use the blockchain to automatically mint NFTs.
Conclusion
In this section, we went over how we can manually mint an NFT using a script. This works great for minting a set of NFTs for testing or for Early Adopters, but doesn’t scale well if you want to make a more dynamic NFT experience.
In the next sections, we will investigate how to use the same mintasset action in a Smart Contract.
Next post: Using AtomicAssets in a Smart Contract
E-book
Get this entire WAX tutorial as an e-book on Amazon.
Additional links
- Github: https://github.com/CapsuleCat/wax-nft-tutorial/blob/main/babychicks/scripts/src/050-mint-chick-egg.js
- Documentation: https://github.com/pinknetworkx/atomicassets-contract/wiki/Actions#mintasset
- Further reading: https://developer.wax.io/build/tutorials/howto_atomicassets/mint_nft.html
- Photo by Sergey Zolkin on Unsplash
Top comments (0)