Theme

Candy Machine Guides

Airdrops - How to Mint NFTs to another Wallet

This guide explains how to mint NFTs from a Candy Machine to different wallet addresses - a common requirement for airdrops, giveaways, or distributing NFTs to multiple recipients.

Prerequisites

  • Basic understanding of Solana and NFTs
  • A funded wallet for transaction fees

either

  • Sugar CLI (v2.0.0 or higher)

or

  • Node.js 16.0 or higher
  • @metaplex-foundation/mpl-token-metadata
  • @metaplex-foundation/mpl-toolbox
  • @metaplex-foundation/umi-bundle-defaults
  • @metaplex-foundation/mpl-candy-machine

Minting NFTs to another wallet can be particularly useful for airdrops, giveaways, or distributing NFTs to multiple recipients. This guide will walk you through the process of minting NFTs from a Candy Machine to a different wallet address. It is important to note that the person initiating the minting process will bear the minting cost. Therefore, it is often more cost-effective to have the recipient claim the NFT themselves.

Important Consideration

  • Minting to another wallet can be expensive. You might want to consider using a claim mechanic instead, e.g. using allowlist or the NFT Gate Guard.
  • There are different tools available for Candy Machines with or without guards. Minting without guards is generally easier.

There are two approaches described in this guide:

  1. Mint using Sugar CLI. No Coding required!
  2. Mint using Javascript

Using Sugar CLI

The Sugar CLI provides two main commands for minting NFTs to other wallets:

  1. sugar mint to mint to one specific wallet
  2. sugar airdrop to mint to multiple wallets

Prerequisite to allow minting through sugar is to have your Candy Machine created without guard attached. To create a Candy Machine with sugar you can follow the first steps of this Guide. If your Candy Machine has guards attached they can be removed using sugar guard remove.

Single Recipient Minting with sugar mint

To mint NFTs to a single recipient wallet, use the sugar mint command with these parameters:

  • --receiver <WALLET>: Specify the recipient's wallet address
  • --number <NUMBER>: (Optional) Specify how many NFTs to mint to that wallet

Example:

To mint 3 NFTs to the wallet Tes1zkZkXhgTaMFqVgbgvMsVkRJpq4Y6g54SbDBeKVV one would call:

sugar mint --receiver Tes1zkZkXhgTaMFqVgbgvMsVkRJpq4Y6g54SbDBeKVV -n 3 --candy-machine 11111111111111111111111111111111

Multiple Recipients with sugar airdrop

To mint NFTs to multiple wallets in a single command sugar airdrop can be used. It requires a file containing the addresses and the amount of NFTs each wallet should receive. A file like this could for example be created by snapshotting the owners of NFTs in a specific collection and adding their wallets and NFTs they hold into a file in the following format:

{
  "11111111111111111111111111111111": 3,
  "22222222222222222222222222222222": 1
}

By default sugar expects this file to be called airdrop_list.json but if if you wish to use a file of which has a different file name you can pass the file name in using --airdrop-list.

Example: To execute this airdrop the following command can be used

sugar airdrop --candy-machine 11111111111111111111111111111111

Using Typescript and @metaplex-foundation/mpl-candy-machine

In this section the code Snippets for the mint functions in Javascript are shown. Both examples also include a full code snippet where a Candy Machine is created and afterwards a single NFT is minted to a specific wallet. To implement a full blown airdrop script one needs to implement loops and error handling around the mint function.

When minting to another wallet using Typescript, there are two main approaches depending on whether your Candy Machine uses guards:

Mint without guards

For Candy Machines without guards, use mintFromCandyMachineV2. This function allows you to directly specify the recipient as the nftOwner.

const candyMachineAccount = await fetchCandyMachine(umi, publicKey("CM Address"));

const recipient = publicKey('Tes1zkZkXhgTaMFqVgbgvMsVkRJpq4Y6g54SbDBeKVV')
const nftMint = generateSigner(umi)
const mintTx = await transactionBuilder()
  .add(setComputeUnitLimit(umi, { units: 800_000 }))
  .add(createMintWithAssociatedToken(umi, { mint: nftMint, owner: recipient }))
  .add(
    mintV2(umi, {
      candyMachine: candyMachineAccount.publicKey,
      nftMint,
      token: findAssociatedTokenPda(umi, {
        mint: nftMint.publicKey,
        owner: recipient,
      }),
      collectionMint: candyMachineAccount.collectionMint,
      collectionUpdateAuthority: candyMachineAccount.authority,
      tokenStandard: TokenStandard.NonFungible,
      mintArgs: {
        mintLimit: some({ // The guards that require mintArgs have to be specified here 
          id: 1,
        }),
      },
    })
  )
  .sendAndConfirm(umi, {
    confirm: { commitment: 'finalized' },
  })

Mint with Guards

For Candy Machines with guards mintV2 can be used. In this case, you'll need to first create the Token Account and Associated Token Account for the recipient using createMintWithAssociatedToken. This allows the recipient to receive the NFT without having to sign the transaction.

const candyMachineAccount = await fetchCandyMachine(umi, publicKey("CM Address"));

const recipient = publicKey('Tes1zkZkXhgTaMFqVgbgvMsVkRJpq4Y6g54SbDBeKVV')
const nftMint = generateSigner(umi)
const mintTx = await transactionBuilder()
  .add(setComputeUnitLimit(umi, { units: 800_000 }))
  .add(createMintWithAssociatedToken(umi, { mint: nftMint, owner: recipient }))
  .add(
    mintFromCandyMachineV2(umi, {
      candyMachine: candyMachine.publicKey,
      mintAuthority: umi.identity,
      nftOwner: recipient,
      nftMint,
      collectionMint: candyMachineAccount.collectionMint,
      collectionUpdateAuthority: candyMachineAccount.authority,
    })
  )
  .sendAndConfirm(umi, {
    confirm: { commitment: 'finalized' },
  })