Actions
Minting Assets from a Candy Machine
Note: Minting can only begin after all assets have been loaded into the Candy Machine. If you missed this step, refer to Loading Items in the Candy Machine
Minting Assets from a Candy Machine
When the Candy Machine has no guards, only the mintAuthority
can mint from it. This can be done using the mintAssetFromCandyMachine()
instruction while explicitly specifying who will receive the asset (assetOwner
).
Here is an example of how to mint from a Core Candy Machine directly:
Mint from a Core Candy Machine
import { mintAssetFromCandyMachine } from '@metaplex-foundation/mpl-core-candy-machine'
import { transactionBuilder, generateSigner } from '@metaplex-foundation/umi'
const candyMachineId = publicKey('11111111111111111111111111111111')
const coreCollection = publicKey('22222222222222222222222222222222')
const asset = generateSigner(umi)
await mintAssetFromCandyMachine(umi, {
candyMachine: candyMachineId,
mintAuthority: umi.identity,
assetOwner: umi.identity.publicKey,
asset,
collection: coreCollection,
}).sendAndConfirm(umi);
with guards
When a Candy Machine has guards, its mintAuthority
is transferred to the associated Candy Guard account. This ensures that all configured rules are enforced before minting, which is why we're using a different instruction (mintV1
).
Depending on the guards configured in the Candy Guard account, additional guard-specific parameters and accounts may be required for the minting process. Below is a list of the extra parameters that may be needed for each guard:
Note: Due to the extra parameters and data required by the transaction, adding more Candy Guards will increase the need for additional compute units.
Here is an example of how to mint from a Core Candy Machine with Guards that requires additional paramters:
Mint from a Core Candy Machine with guards
import {
some,
generateSigner,
} from '@metaplex-foundation/umi'
import { mintV1 } from '@metaplex-foundation/mpl-core-candy-machine'
const candyMachineId = publicKey('11111111111111111111111111111111')
const coreCollection = publicKey('22222222222222222222222222222222')
const asset = generateSigner(umi)
await mintV1(umi, {
candyMachine: candyMachineId,
asset,
collection: coreCollection,
mintArgs: {
thirdPartySigner: some({ signer: thirdPartySigner }),
mintLimit: some({ id: 1 }),
},
}).sendAndConfirm(umi)
with guard groups
When a Candy Machine has guard groups, same as minting with guards its mintAuthority
is transferred to the associated Candy Guard account and depending on the guards, additional guard-specific parameters and accounts may be required for the minting process.
The main difference between the two types is that when using guard groups, we must explicitly select which group we want to mint from by providing its label. Additionally the guard-specific parameters that needs to be added are specific to the choosen group.
For example, for a Candy Machine with the following guards:
- Default Guards: Bot Tax, Third Party Signer, Start Date
- Group 1 - Label: nft: NFT Payment, Start Date
- Group 2 - Label: public: Sol Payment
The "Resolved Guards" of Group 1 — labelled “nft” — are:
- Bot Tax: from the Default Guards.
- Third Party Signer: from the Default Guards.
- NFT Payment: from Group 1.
- Start Date: from Group 1 because it overrides the default guard.
Therefore, the guard-specific parameters must be related only to these Resolved Guards.
Here is an example of how to mint from a Core Candy Machine with guard groups that requires additional paramters:
Mint from a Core Candy Machine with guard groups
import {
some,
generateSigner,
} from '@metaplex-foundation/umi'
import { mintV1 } from '@metaplex-foundation/mpl-core-candy-machine'
const candyMachineId = publicKey('11111111111111111111111111111111')
const coreCollection = publicKey('22222222222222222222222222222222')
const asset = generateSigner(umi)
await mintV1(umi, {
candyMachine: candyMachineId,
asset,
collection: coreCollection,
group: some('nft'),
mintArgs: {
thirdPartySigner: some({ signer: thirdPartySigner }),
nftPayment: some({
mint: nftFromRequiredCollection.publicKey,
destination: nftTreasury,
tokenStandard: TokenStandard.NonFungible,
}),
},
}).sendAndConfirm(umi)
with pre-validation
For pre-validation, we mean all the guards that may require additional verification steps before the mint like creating an account getting a token that acts as proof of that verification.
This can be done in two ways:
- Using the route instruction: An example of this is the Allowlist Guard that needs to verify that the wallet belongs to the allowlist providing a valid Merkle Proof. If the route instruction is successful, it will create an Allowlist PDA linked with the wallet wich the Candy Machine instruction will read and validate during the mint.
- Using External Services: An example of this is the Gatekeeper Guard that request a Gateway Token by performing a challenge — such as completing a Captcha — which depends on the configured Gatekeeper Network. The Gatekeeper guard will then check for the existence of such Gateway Token to either validate or reject the mint.
The Bot Tax
The Bot Tax Guard protects your Candy Machine against bots by charging mints, that failed because of a Guard, a configurable amount of SOL. All the Sol collected is transferred to the Candy Machine and is accessible by closing the account.
Note: When the Bot Tax Guard gets activated, the transaction will pretend to succeed, this means no errors will be returned by the program but no NFT will be minted either. This is because the transaction must succeed for the funds to be transferred from the bot to the Core Candy Machine account.