How to Mint NFTs to Another Wallet - Airdrop example
Overview
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
Either
Basic understanding of Solana and NFTs
A funded wallet for transaction fees
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.
- 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:
- Mint using sugar CLI
- Mint using Javascript
Using Sugar CLI
The Sugar CLI provides two main commands for minting NFTs to other wallets:
sugar mint
to mint to one specific walletsugar airdrop
to mint to multiple wallets
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 NFT to 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:
{
"22222222222222222222222222222222": 3,
"33333333333333333333333333333333": 1
}
By default sugar expects this file to be called airdrop_list.json
. This default name can be changed with --airdrop-list
.
Example: To execute this airdrop the following command can be used
sugar airdrop --candy-machine 11111111111111111111111111111111
Using Typescript and mpl-candy-machine
In this section the code Snippets for 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 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, use mintV2
. 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' },
})
{% /totem %