介绍
在最后一部分中,我们创建了我们的收藏。接下来,我们将创建一些脚本来创建我们的AtomicAssets架构。在我们的小鸡NFT示例中,我们将创建2个模式:小鸡和小鸡。
鸡蛋将代表NFT的购买,而小鸡NFT将从鸡蛋中孵化。无论如何,将鸡蛋nft和小鸡的nft分成两个不同的模式让我们的薄荷nfts在我们喜欢的情况下:我们可以预先涂上所有的小鸡鸡蛋并将它们抽出,我们可以动态地创建一个小鸡鸡蛋NFT作为一部分蜡销售。但是,您想出售NFT取决于您,但是将它们分开,可以使您可以将购买与用户收到的稀有性分开。
理解创建的气息
让我们看一下createschema
架构。
就像以前一样,我们需要在编写脚本时填写所有这些信息。让我们看一下每个领域:
-
authorized_creator
-在我们的示例中,作者将与我们上次示例的付款人相同:waxcourse123
。这应该是您的帐户名称,或以前的收藏创建步骤中的授权帐户。 -
collection_name
-与以前相同,babychicknft
。 -
schema_name
-这是我们模式的名称。我们将拥有一个babychick
和chickegg
。 -
schema_format
-这将描述我们的小鸡和小鸡鸡蛋所具有的一系列属性。要与Atomichub完全集成,它应该至少具有name
和img
。
我们将从小鸡蛋NFT开始。这是我们将用来创建鸡蛋的模式:
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" }
];
此架构将定义一个鸡蛋,即在创建鸡蛋NFT时可以填写的名称,图像,描述,URL和社交。
接下来,让我们看一下小鸡模式:
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" },
];
您会注意到,许多NFT集合和模式都会有一组共同的属性:
- 名称
- img
- 描述
- 社会
- url
这在Atomichub上相当普遍,其中许多属性将自动检测并在Atomichub Web UI中使用。
脚本Chickegg模式
我们将在上一个集合脚本上构建以创建一个用于创建鸡蛋架构的脚本:
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);
})()
脚本录制babychick模式
和小鸡模式:
创建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);
})()
运行脚本
类似于我们的集合脚本,我们希望将它们与环境变量调用:
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
示例响应:
结论
在本节中,我们创建了两个模式:babychicks和chickeggs。现在我们有了模式,我们可以转向为每个模式创建模板。
其他链接
- github:habhabioqian11
- https://github.com/CapsuleCat/wax-nft-tutorial/blob/main/babychicks/scripts/src/020-create-baby-chick-schema.js
- 文档:https://github.com/pinknetworkx/atomicassets-contract/wiki/Actions#createschema
- 进一步阅读:https://developer.wax.io/build/tutorials/howto_atomicassets/schemas_js.html
- Joshua Woroniecki上的Unsplash摄影