# Freeze Token Payment Guard

Frozen Assets cannot be transferred or listed on any marketplaces until thawed.

Frozen Assets can be thawed by anyone as long as one of the following conditions is met:

* The Candy Machine has minted out.
* The Candy Machine was deleted.
* The configured Freeze Period — which can be a maximum of 30 days — has passed.

The tokens are transferred to a "Freeze Escrow" account which must be initialized by the Candy Guard authority before minting can start. Once all Frozen Assets have been thawed, the funds can be unlocked and transferred to the configured destination account by the Candy Guard authority.

You may initialize the Freeze Escrow account, thaw Assets and unlock funds [via the route instruction](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#route-instruction) of this guard.

Initialize Freeze Escrow

①

Freeze Escrow PDA

Funds are transferred

to the escrow account

Mint Frozen Assets

②

Frozen AssetFrozen AssetFrozen Asset🕑

*When all Assets have been minted*

*OR at the end of the freeze period.*

Thaw Assets

③

Thawed AssetThawed AssetThawed Asset🕑

*When all Assets have been thawed.*

Unlock Funds

④

Freeze Escrow PDATreasury[React Flow](https://reactflow.dev/)

### Guard Settings <a href="#guard-settings" id="guard-settings"></a>

The Freeze Token Payment guard contains the following settings:

* **Amount**: The number of tokens to charge the payer.
* **Mint**: The address of the mint account defining the SPL Token we want to pay with.
* **Destination Associated Token Address (ATA)**: The address of the associated token account to eventually send the tokens to. We can get this address by finding the Associated Token Address PDA using the **Mint** attribute and the address of any wallet that should receive these tokens.

Set up a Candy Machine using the Freeze Token Payment guard

JavaScript

Here’s how we can create a Candy Machine using the Freeze Token Payment guard. Note that, in this example, we’re using Umi's identity as the destination wallet.

```
import { findAssociatedTokenPda } from "@metaplex-foundation/mpl-toolbox";

create(umi, {
  // ...
  guards: {
    freezeTokenPayment: some({
      amount: 300,
      mint: tokenMint.publicKey,
      destinationAta: findAssociatedTokenPda(umi, {
        mint: tokenMint.publicKey,
        owner: umi.identity.publicKey,
      }),
    }),
  },
});
```

### Mint Settings <a href="#mint-settings" id="mint-settings"></a>

The Freeze Token Payment guard contains the following Mint Settings:

* **Mint**: The address of the mint account defining the SPL Token we want to pay with.
* **Destination Associated Token Address (ATA)**: The address of the associated token account to eventually send the tokens to.

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](https://github.com/metaplex-foundation/mpl-core-candy-machine/tree/main/programs/candy-guard#freezetokenpayment) for more details.

Set up a Candy Machine using the Freeze Token Payment Guard

JavaScript

You may pass the Mint Settings of the Freeze Token Payment guard using the `mintArgs` argument like so.

```
mintV1(umi, {
  // ...
  mintArgs: {
    freezeTokenPayment: some({
      mint: tokenMint.publicKey,
      destinationAta,
    }),
  },
});
```

### Route Instruction <a href="#route-instruction" id="route-instruction"></a>

The Freeze Token Payment route instruction supports the following features.

* [Overview](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#overview)
* [Guard Settings](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#guard-settings)
* [Mint Settings](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#mint-settings)
* [Route Instruction](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#route-instruction)
  * [Initialize the Freeze Escrow](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#initialize-the-freeze-escrow)
  * [Thaw a Frozen Asset](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#thaw-a-frozen-asset)
  * [Unlock Funds](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#unlock-funds)
* [Stop Freezing Assets](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#stop-freezing-assets)
* [Freeze Escrows and Guard Groups](https://developers.metaplex.com/core-candy-machine/guards/freeze-token-payment#freeze-escrows-and-guard-groups)

#### Initialize the Freeze Escrow <a href="#initialize-the-freeze-escrow" id="initialize-the-freeze-escrow"></a>

*Path: `initialize`*

When using the Freeze Token Payment guard, we must initialize the Freeze Escrow account before minting can start. This will create a PDA account derived from the Destination ATA attribute of the guard's settings.

The Freeze Escrow PDA account will keep track of several parameters such as:

* How many Frozen Assets were minted through this guard.
* When was the first Frozen Asset minted via this guard as the Freeze Period starts counting after that.

When initializing this Freeze Escrow account, we must provide the following arguments to the route instruction of the guard:

* **Path** = `initialize`: Selects the path to execute in the route instruction.
* **Mint**: The address of the mint account defining the SPL Token we want to pay with.
* **Destination Associated Token Address (ATA)**: The address of the associated token account to eventually send the tokens to.
* **Period**: The amount of time in seconds that the Freeze Period should last. This can be a maximum of 30 days (2,592,000 seconds) and it will start from the very first Frozen Asset minted via this guard. The Freeze Period provides a safety mechanism to ensure Frozen Assets can eventually be thawed even if the Candy Machine never mints out.
* **Candy Guard Authority**: The authority of the Candy Guard account as a Signer.

Candy Machine

Owner: Candy Machine Core Program

Candy GuardOwner: Candy Guard ProgramGuardsFreeze Token PaymentAmount = 300MintDestination ATA...

Route with Path

\= *Initialize*

Candy Machine Guard Program

Initialize Freeze Escrow

Freeze Period

Freeze Escrow PDA

[React Flow](https://reactflow.dev/)

Last but not least, the Freeze Escrow PDA account will receive the funds of all Frozen Assets minted through this guard.

Candy Machine

Owner: Candy Machine Core Program

Candy GuardOwner: Candy Guard ProgramGuardsFreeze Token PaymentAmount = 300MintDestination ATA...

Freeze Escrow PDA

Route with

Path = *Initialize*

Candy Machine Guard Program

Access Control

Transfer 300 tokens

to the Freeze Escrow's

Associated Token Address

Mint

Candy Machine Core Program

Mint Logic

Frozen Asset

[React Flow](https://reactflow.dev/)

Initialize the Freeze Escrow

JavaScript

In the example below, we initialize the Freeze Escrow account with a maximum Freeze Period of 15 days and we use the current identity as the Core Candy Guard authority.

```
route(umi, {
  // ...
  guard: "freezeTokenPayment",
  routeArgs: {
    path: "initialize",
    mint: tokenMint.publicKey,
    destinationAta,
    period: 15 * 24 * 60 * 60, // 15 days.
    candyGuardAuthority: umi.identity,
  },
});
```

#### Thaw a Frozen Asset <a href="#thaw-a-frozen-asset" id="thaw-a-frozen-asset"></a>

*Path: `thaw`*

Frozen Assets can be thawed by anyone as long as one of the following conditions is met:

* The Core Candy Machine has minted out.
* The Core Candy Machine was deleted.
* The configured Freeze Period — which can be a maximum of 30 days — has passed.

Note that since the tokens in the Freeze Escrow are not transferrable until all Assets are thawed, this creates an incentive for the treasury to thaw all Assets as soon as possible.

To thaw a Frozen Asset, we must provide the following arguments to the route instruction of the guard:

* **Path** = `thaw`: Selects the path to execute in the route instruction.
* **Mint**: The address of the mint account defining the SPL Token we want to pay with.
* **Destination Associated Token Address (ATA)**: The address of the associated token account to eventually send the tokens to.
* **Asset Adress**: The mint address of the Frozen Asset to thaw.
* **Asset Owner**: The address of the owner of the Frozen Asset to thaw.

Candy Machine

Candy Machine Core Program

Candy Guard

Candy Machine Guard Program

GuardsFreeze Token PaymentAmount = 300MintDestination ATA...

Route with

Path = *thaw*

Candy Machine Core Program

Thaw a Frozen Asset

Freeze Escrow PDAFrozen AssetThawed Asset[React Flow](https://reactflow.dev/)

Set up a Candy Machine using the Freeze Token Payment guard

JavaScript

In the example below, we thaw a Frozen Asset that belongs to the current identity.

```
route(umi, {
  // ...
  guard: "freezeTokenPayment",
  routeArgs: {
    path: "thaw",
    mint: tokenMint.publicKey,
    destinationAta,
    AssetMint: AssetMint.publicKey,
    AssetOwner: umi.identity.publicKey,
    AssetTokenStandard: candyMachine.tokenStandard,
  },
});
```

#### Unlock Funds <a href="#unlock-funds" id="unlock-funds"></a>

*Path: `unlockFunds`*

Once all Frozen Assets have been thawed, the treasury can unlock the funds from the Freeze Escrow account. This will transfer the tokens to the configured Destination ATA address.

To unlock the funds, we must provide the following arguments to the route instruction of the guard:

* **Path** = `unlockFunds`: Selects the path to execute in the route instruction.
* **Mint**: The address of the mint account defining the SPL Token we want to pay with.
* **Destination Associated Token Address (ATA)**: The address of the associated token account to eventually send the tokens to.
* **Candy Guard Authority**: The authority of the Core Candy Guard account as a Signer.

Candy Machine

Owner: Candy Machine Core Program

Candy Guard

Candy Machine Guard Program

GuardsFreeze Token Payment- Amount- Mint- Destination ATA...

Route with

Path = *unlockFunds*

Candy Machine Guard Program

Unlock funds

from the escrow

Freeze Escrow PDAMint Account

Owner: Token Program

Token Account

Owner: Token Program

Destination Wallet

Owner: Candy Machine Core Program

Transfer all funds from

the Freeze Escrow Account

[React Flow](https://reactflow.dev/)

Set up a Candy Machine using the Freeze Token Payment Guard

JavaScript

In the example below, we unlock the funds from the Freeze Escrow account using the current identity as the Candy Guard authority.

```
route(umi, {
  // ...
  guard: 'freezeTokenPayment',
  routeArgs: {
    path: 'unlockFunds',
    destination,
    candyGuardAuthority: umi.identity,
  },
})
```

API References: [route](https://mpl-core-candy-machine.typedoc.metaplex.com/functions/route.html), [freezeTokenPaymentRouteArgsUnlockFunds](https://mpl-core-candy-machine.typedoc.metaplex.com/types/freezeTokenPaymentRouteArgsUnlockFunds.html)

### Stop Freezing Assets <a href="#stop-freezing-assets" id="stop-freezing-assets"></a>

It is possible to stop the freezing of Assets within a Freeze Token Payment guard. In other words, new-minted Assets will no longer be frozen but **existing Frozen Assets will remain frozen**.

There are several ways of achieving this, which can be separated into two categories:

* ☀️ **Can Thaw**: Existing Frozen Assets can be thawed by anyone using the `thaw` path of the route instruction.
* ❄️ **Cannot Thaw**: Existing Frozen Assets cannot be thawed yet and we have to wait for one "Can Thaw" condition to be met.

With that in mind, here is the exhaustive list of ways to stop freezing Assets and whether or not each of them allows thawing existing Frozen Assets:

* The Candy Machine has minted out → ☀️ **Can Thaw**.
* The configured Freeze Period — which can be a maximum of 30 days — has passed → ☀️ **Can Thaw**.
* The Candy Machine account was deleted → ☀️ **Can Thaw**.
* The Candy Guard account was deleted → ❄️ **Cannot Thaw**.
* The Freeze Token Payment guard was removed from the settings → ❄️ **Cannot Thaw**.

### Freeze Escrows and Guard Groups <a href="#freeze-escrows-and-guard-groups" id="freeze-escrows-and-guard-groups"></a>

When using multiple Freeze Token Payment guards within various [Guard Groups](https://developers.metaplex.com/core-candy-machine/guard-groups), it is important to understand the relationship between a Freeze Token Payment guard and a Freeze Escrow account.

The Freeze Escrow account is a PDA derived from a Destination address. This means that if **multiple Freeze Token Payment guards** are configured to use the **same Destination address**, they will all **share the same Freeze Escrow account**.

Therefore, they will also share the same Freeze Period and all funds will be collected by the same escrow account. This also means, we only need to call the `initialize` route instruction once per configured Destination address.This implies that the route instruction is only required once per the configured Destination address. Same applies for `unlockFunds`. To `thaw` you can use whichever label you like provided that those shared the same escrow account.

It is also possible to use multiple Freeze Token Payment guards with different Destination addresses. In this case, each Freeze Token Payment guard will have its own Freeze Escrow account and its own Freeze Period.

The example below illustrates a Candy Machine with three Freeze Token Payment guards in three groups such that:

* Groups 1 and 2 share the same Destination address and therefore the same Freeze Escrow account.
* Group 3 has its own Destination address and therefore its own Freeze Escrow account.

Candy Machine

Owner: Candy Machine Core Program

Candy GuardOwner: Candy Guard ProgramGuard Group 1Freeze Token PaymentAmount = 300MintDestination ATA A...Guard Group 2Freeze Token PaymentAmount = 300MintDestination ATA A...Guard Group 3Freeze Token PaymentAmount = 300MintDestination ATA B...

Freeze Escrow PDA

For Destination A

Route with

Path = *Initialize*

Candy Machine Guard Program

Initialize Freeze Escrow

Freeze Period A

Freeze Escrow PDA

For Destination B

Route with

Path = *Initialize*

Candy Machine Guard Program

Initialize Freeze Escrow

Freeze Period B

<br>
