Skip to main content

Token Gate

info

A newer version of this page is available in the Developer Hub. Click here to read it.

Overview

The Token Gate guard restricts minting to token holders of a configured mint account. If the payer does not have the required amount of tokens, minting will fail.

CandyMachinesV3-GuardsTokenGate.png

Guard Settings

The Token Gate guard contains the following settings:

  • Amount: The number of tokens required.
  • Mint: The address of the mint account defining the SPL Token we want to gate with.

JavaScript — Umi library (recommended)

Here’s how we can set up a Candy Machine using the Token Gate guard.

create(umi, {
// ...
guards: {
tokenGate: some({
amount: 300,
mint: tokenMint.publicKey,
}),
},
});

API References: create, TokenGate

JavaScript — SDK

Here’s an example of how to set up a Candy Machine using the Token Gate guard.

import { token } from "@metaplex-foundation/js";

const { candyMachine } = await metaplex.candyMachines().create({
// ...
guards: {
tokenGate: {
amount: token(300),
mint: tokenMint.address,
},
},
});

API References: Operation, Input, Output, Transaction Builder, Guard Settings.

Mint Settings

The Token Gate guard contains the following Mint Settings:

  • Mint: The address of the mint account defining the SPL Token we want to gate with.

Note that, if you’re planning on constructing instructions without the help of our SDKs, you will need to provide these Mint Settings and more as a combination of instruction arguments and remaining accounts. See the Candy Guard’s program documentation for more details.

JavaScript — Umi library (recommended)

You may pass the Mint Settings of the Token Gate guard using the mintArgs argument like so.

mintV2(umi, {
// ...
mintArgs: {
tokenGate: some({ mint: tokenMint.publicKey }),
},
});

API References: mintV2, TokenGateMintArgs

JavaScript — SDK

The JS SDK does not require any Mint Settings for the Token Gate guard since it can infer them from the provided Candy Machine model.

Route Instruction

The Token Gate guard does not support the route instruction.