Creating AtomicAssets Schemas
Ivan Montiel
Posted on August 6, 2023
Introduction
In the last section, we created our Collection. Next we will create some scripts to create our AtomicAssets Schema. In our Baby Chicks NFT example, we’ll create 2 schemas: Chick Egg and Baby Chick.
A Chick Egg will represent an NFT purchase, and the Baby Chick NFT will be “hatched” from the egg. Separating the Egg NFT and the Chick NFT into two distinct schemas let’s us mint NFTs in anyway we like: we could pre-mint all the Chick Eggs and raffle them off, we could dynamically create a Chick Egg NFT as part of a WAX sale. However you want to sell your NFTs is up to you, but having them separate lets you separate the purchase from the rarity a user will receive.
Understanding createschema
Let’s look at the createschema
schema to start with.
Like before, we will need to fill in all of this information when we write our script. Let’s take a look at each field:
-
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 ababychick
andchickegg
. -
schema_format
- this will describe the set of attributes that our Baby Chicks and Chick Eggs will have. To fully integrate with AtomicHub, it should have at a minimum aname
andimg
.
We’ll start with the Chick Egg NFT. Here is a schema we will use to create our eggs:
const schema = [
{ "name": "name", "type": "string" },
{ "name": "img", "type": "image" },
{ "name": "description", "type": "string" },
{ "name": "url", "type": "string" },
{ "name": "socials", "type": "string" },
{ "name": "created_at", "type": "uint64" }
];
This schema will define an egg as having a name, image, description, urls, and socials that we can fill in when we create an egg NFT.
Next, let’s look at the baby chick schema:
const schema = [
{ "name": "name", "type": "string" },
{ "name": "img", "type": "image" },
{ "name": "description", "type": "string" },
{ "name": "rarity", "type": "string" },
{ "name": "url", "type": "string" },
{ "name": "socials", "type": "string" },
{ "name": "created_at", "type": "uint64" },
{ "name": "hp", "type": "uint64" },
{ "name": "color", "type": "string" },
{ "name": "weight", "type": "uint64" },
];
You’ll notice that many NFT collections and schemas will have a common set of attributes:
- name
- img
- description
- socials
- url
This is fairly common across AtomicHub and many of these attributes will be automatically detected and used in the AtomicHub web UI.
Scripting the ChickEgg Schema
We will build on the previous collection script to create a script for creating the egg schema:
create-chick-egg-schema.js
import { transact } from "./utilities/transact";
import { name } from "./utilities/name";
const schema = [
{ "name": "name", "type": "string" },
{ "name": "img", "type": "image" },
{ "name": "description", "type": "string" },
{ "name": "url", "type": "string" },
{ "name": "socials", "type": "string" },
{ "name": "created_at", "type": "uint64" }
];
async function createChickEggSchema() {
const author = process.env.WAX_ACCOUNT;
if (!author) {
throw new Error("Missing WAX_ACCOUNT");
}
try {
await transact([
{
account: "atomicassets",
name: "createschema",
authorization: [
{
actor: author,
permission: "active",
},
],
data: {
authorized_creator: author,
collection_name: collectionName('babychicknft'),
schema_name: name('chickegg'),
schema_format: schema
},
},
])
} catch (error) {
console.error(error);
return false;
}
}
(async () => {
const result = await createChickEggSchema();
console.log(result);
})()
Scripting the BabyChick Schema
And for the baby chick schema:
create-baby-chick-schema.js
import { transact } from "./utilities/transact";
import { name } from "./utilities/name";
const schema = [
{ "name": "name", "type": "string" },
{ "name": "img", "type": "image" },
{ "name": "description", "type": "string" },
{ "name": "rarity", "type": "string" },
{ "name": "url", "type": "string" },
{ "name": "socials", "type": "string" },
{ "name": "created_at", "type": "uint64" },
{ "name": "hp", "type": "uint64" },
{ "name": "color", "type": "string" },
{ "name": "weight", "type": "uint64" },
]
async function createBabyChickSchema() {
const author = process.env.WAX_ACCOUNT;
if (!author) {
throw new Error("Missing WAX_ACCOUNT");
}
try {
await transact([
{
account: "atomicassets",
name: "createschema",
authorization: [
{
actor: author,
permission: "active",
},
],
data: {
authorized_creator: author,
collection_name: collectionName('babychicknft'),
schema_name: name('babychick'),
schema_format: schema
},
},
])
} catch (error) {
console.error(error);
return false;
}
}
(async () => {
const result = await createBabyChickSchema();
console.log(result);
})()
Running the Scripts
Similar to our collection scripts, we will expect them to be called with Environment variables:
WAX_ACCOUNT=waxcourse123 \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT="https://testnet.wax.pink.gg" \
node ./src/010-create-chick-egg-schema.js
WAX_ACCOUNT=waxcourse123 \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT="https://testnet.wax.pink.gg" \
node ./src/020-create-baby-chick-schema.js
Example responses:
Conclusion
In this section, we created two schemas: BabyChicks and ChickEggs. Now that we have the schemas, we can move onto creating templates for each schema.
Next post: Create an AtomicAssets Template
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/010-create-chick-egg-schema.js
- https://github.com/CapsuleCat/wax-nft-tutorial/blob/main/babychicks/scripts/src/020-create-baby-chick-schema.js
- Documentation: https://github.com/pinknetworkx/atomicassets-contract/wiki/Actions#createschema
- Further reading: https://developer.wax.io/build/tutorials/howto_atomicassets/schemas_js.html
- Photo by Joshua Woroniecki on Unsplash
Posted on August 6, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.