可用守卫

配额守卫

概述

Allocation 守卫允许指定每个守卫组可以铸造的资产数量限制。

限制是按标识符设置的——在设置中提供——以允许在同一个 Core Candy Machine 中进行多个配额分配。

守卫设置

Allocation 守卫包含以下设置:

  • ID:此守卫的唯一标识符。不同的标识符将使用不同的计数器来跟踪给定钱包铸造了多少物品。这在使用守卫组时特别有用,因为我们可能希望每个组都有不同的铸造限制。
  • Limit:守卫组允许的最大铸造数量。

使用 Allocation 守卫设置 Candy Machine

create(umi, {
// ...
guards: {
allocation: some({ id: 1, limit: 5 }),
},
});

API 参考:createAllocation

铸造设置

Allocation 守卫包含以下铸造设置:

  • ID:此守卫的唯一标识符。

注意,如果您计划在没有我们 SDK 帮助的情况下构建指令,您需要将这些铸造设置和更多内容作为指令参数和剩余账户的组合提供。详情请参阅 Candy Guard 的程序文档

使用 Allocation 守卫铸造

您可以使用 mintArgs 参数传递 Allocation 守卫的铸造设置,如下所示。

mintV1(umi, {
// ...
mintArgs: {
allocation: some({ id: 1 }),
},
});

Route 指令

Allocation 守卫的 route 指令支持以下功能。

初始化配额追踪器

使用 Allocation 守卫时,我们必须在铸造开始前初始化配额追踪器账户。这将创建一个从守卫设置的 id 属性派生的 PDA 账户。

配额追踪器 PDA 账户将跟踪守卫组中的铸造数量,一旦达到限制,它将阻止该组中的任何铸造。

初始化此配额追踪器账户时,我们必须向守卫的 route 指令提供以下参数:

  • ID:守卫设置中 Allocation 的 id。
  • Candy Guard Authority:Core Candy Guard 账户的授权作为签名者。

初始化配额追踪器 PDA

要为默认守卫初始化配额追踪器 PDA:

route(umi, {
// ...
guard: 'allocation',
routeArgs: {
id: 1,
candyGuardAuthority: umi.identity,
},
})

当 Allocation 守卫添加到特定组时,您需要添加 group 名称:

route(umi, {
// ...
guard: 'allocation',
routeArgs: {
id: 1,
candyGuardAuthority: umi.identity,
},
group: some('GROUPA'),
})

API 参考:routeAllocationRouteArgs

配额账户

当使用 Allocation 守卫时,在运行 route 指令后会创建一个 allocationTracker 账户。出于验证目的,可以这样获取它:

import {
safeFetchAllocationTrackerFromSeeds,
} from "@metaplex-foundation/mpl-core-candy-machine";
const allocationTracker = await safeFetchAllocationTrackerFromSeeds(umi, {
id: 1, // 您在守卫配置中设置的配额 id
candyMachine: candyMachine.publicKey,
// 或者使用您的 CM 地址 candyMachine: publicKey("Address")
candyGuard: candyMachine.mintAuthority,
// 或者使用您的 candyGuard 地址 candyGuard: publicKey("Address")
});