Easy Guide To Mint Solana NFTs Using Candy Machine V2

Real life candy machine

Easy Guide To Mint Solana NFTs Using Candy Machine V2

Candy Machine is a helpful tool developed by Metaplex to streamline minting NFTs on Solana




What Is Solana Candy Machine?

The Solana NFT Candy Machine, or CM for short, is a Solana Program designed to help NFT creators sell their NFTs. The Candy Machine program is similar to a real-world mechanical candy machine whereby a person deposits a coin into the candy machine and gets one piece of candy back. Minting NFT collections correctly requires technical know-how, and the Candy Machine helps streamline the process.

Candy Machine helps solve common issues related to minting Solana NFTs including:

  • accepting a buyers funds when the project was out of NFTs to sell
  • not having a precise and global start time
  • projects were not producing consistent, well formed valid NFTs
  • protection from bot attacks
  • correctly structuring NFT metadata
  • creating on-chain collection NFTs for authentication

Most large-scale NFT creators use automated minting tools similar to Candy Machine. Candy Machine V2 is the second iteration, and it is now a fully on-chain generative NFT distribution program.

What Are The Differences Between Candy Machine V2 and Candy Machine V1?

Candy Machine V2 provides many new features and security upgrades from Candy Machine V1. Version 2 enables you to create new distribution scenarios and offers protection from bot attacks.

Primary feature changes include:

  • Unpredictable NFT mint index: Candy Machine V1 NFT mints were in sequential order, so it was possible to predict the mints. This created the opportunity to choose which NFT to mint. Candy Machine V2 introduces randomness into the minting process to make it difficult for users to guess the NFT mint index.
  • Whitelist: As a Candy Machine creator you can configure a whitelists for pre-approved addresses.
  • Captcha settings: Bots were a real issue with Candy Machine V1. Now Candy Machine V2 is equipped with captcha protection.
  • Larger collections and hide-and-reveal drops: Now you can create large and hide-and-reveal NFT drops by specifying a single hash, which is used by all NFT mints. While the hash is the same across all NFT mints, the name of each item is specified with a unique number, allowing an off-chain process to later update the NFT metadata with the actual item.
  • More configuration options: New settings that allow the definition of rules to pause the NFT mint at a certain point. Candy Machine configuration values can be updated at any time.

Candy Machine V2 Guide

Candy Machine V2 requires installation of several packages to work correctly. Installing and using Solana Candy Machine V2 requires intermediate programming experience - this might be challenging for those who are new to coding. We will walk you through step-by-step how to setup your NFT mint using Candy Machine V2.

The guide uses basic configuration settings to keep it simple. The Metaplex docs can walk you through all advanced options and settings. Also, the Metaplex docs include a section on creating a NFT minting website, which is not covered here.

We highly recommend using Solana devnet to practice deploying Candy Machine and minting NFTs. Do not use Solana mainnet with SOL until you are sure that your local environment is configured properly.

Step 1: Install Requirements

First, let's get started by installing all of the software packages we will need to mint Solana NFTs with Candy Machine:

  • Git: Git is a free and open source distributed version control system.
  • TypeScript Node : TypeScript execution environment.
  • Node.JS: An open-source, cross-platform, back-end JavaScript runtime environment that executes JavaScript code outside a web browser.
  • Yarn: Software packaging system developed in 2016 by Facebook for the Node.js JavaScript runtime environment.
  • Avana Wallet: Non-custodial Solana blockchain wallet to view and send your NFTs once you have minted them 😊.
  • Solana CLI: Command-line interface to interact with Solana blockchain.
  • Metaplex: Command-line interface to interact with Metaplex (covered below in Step 2).

If you are running Mac OS with the Apple M1 Chip, then you need to install additional dependencies (see docs):

brew install pkg-config cairo pango libpng jpeg giflib librsvg

Step 2: Clone & Install Metaplex Candy Machine

Clone the latest Metaplex Candy Machine V2 from the master branch on Github. The project is about 90 megabytes and could take a couple minutes to download.

Create a project directory. We will use the folder "cm-project" mkdir ~/cm-project and then change directory to the project folder root cd ~/cm-project.

Next, let's clone the Metaplex repository including Candy Machine into our project folder git clone . - after the code is finished downloading, run --cwd ./js/ in the project root folder (do not change folders).

You can check to make sure that everything installed properly by running npx ts-node ./js/packages/cli/src/candy-machine-v2-cli.ts --version. The version should print in your command line. For example, the current version as of May 2022 is 0.0.2.

Step 3: Setup Your Solana CLI Wallet

The Metaplex Candy Machine operates on the Solana blockchain. You need to connect your Solana wallet and add funds to create and deploy a Candy Machine. You have two options: use an existing keypair with funds, or create a new keypair and add funds.

Option 1: Use Existing Keypair

You can use an existing wallet by creating a json file with your private key bytes on your computer. For example, you can create ~/.config/solana/keypair.json and enter your private key bytes:

An example of private key bytes for public key 5WfBt2ziAxA4DWV3XBSmvczhjcp9Az9eCcdmgSNvZ2Ar: [180, 188, 199, 250, 25, 20, 136, 163, 252, 250, 217, 250, 119, 201, 94, 93, 72, 21, 129, 51, 164, 68, 226, 171, 46, 13, 131, 29, 116, 73, 182, 179, 67, 7, 197, 31, 63, 237, 61, 33, 216, 49, 246, 99, 32, 27, 234, 216, 114, 191, 31, 139, 251, 72, 229, 160, 79, 145, 203, 25, 172, 248, 76, 143]

Option 2: Create New Keypair

Run solana-keygen new --outfile ~/.config/solana/keypair.json to create a new keypair. This will create a new keypair for you. We are not going to add a BIP39 passphrase to simplify the tutorial.

Create new Solana keypair in command line interface

Make sure you save the output pubkey: 5B2r75JbpajeWcx4niKq7pck3ZLcHvChXATm46YdRLGp. We will need this address later.

Now we need to set keypair.json file as the Solana CLI keypair. Run solana config set --keypair ~/.config/solana/keypair.json.

Then set the Solana RPC connection. We will use solana config set --url to connect to Solana devnet. Any other RPC provider works for this tutorial as well. Note that you should use an alternative RPC connection (not public Solana RPC) if you plan on minting large collections. The Solana devnet RPC connection is not reliable.

If you created a new wallet and you are using devnet, make sure you add Solana SOL to your wallet. We can add SOL by running solana airdrop 1. Run this five times to add 5 SOL (let about 30 seconds pass between requests). The Solana airdrop command is sometimes unreliable. If the command does not work, you can use the airdrop tool at

Step 4: Configuring Candy Machine

Candy Machine V2 is now configured in a single JSON file - this is a change from Candy Machine V1. You can save and reuse the configuration across multiple drops. There is a single account on-chain that holds all the configuration of a Candy Machine and you can make changes to your configuration in the future. Configuring Candy Machine is very important, so double and triple check your settings.

Below is an example configuration for Candy Machine V2. You can find all configuration options at Metaplex Docs. The settings we need to update include:

  • goLiveDate: Add the date you want your mint to go live. Make sure you keep the date formatting consistent with the example.
  • price: Add price per item in Solana SOL.
  • number: Number of items you will mint.
  • solTreasureAccount: Replace Your Wallet Address with the address from Step 3.
  • noRetainAuthority: False means you keep the role as update authority. True means you do not keep the role.
  • noMutable: False means you can update the on-chain metadata. True means the on-chain metadata is frozen.
  • storage: The storage provider that holds your off-chain NFT metadata and image.
Sample Solana Candy Machine Configuration JSON file

The settings above will configure a Candy Machine V2 to operate in a similar way as Candy Machine V1, but the mint order will be unpredictable. You can download a sample config file here: config.json. This tutorial is going to walk you through the basic steps to create a Candy Machine mint. There are more advanced options such as Whitelist Settings, End Settings, Hidden Settings, Captcha Protection and Gatekeeper Settings in the Metaplex documentation. Also, if you have an issue deploying your NFT collection using storage provider arweave-sol, you can try using arweave.

Step 5: Preparing Your NFT Images & Metadata

The Candy Machine makes it very easy to upload a collection of images and their metadata from your computer to the Solana blockchain and file storage provider. The Candy Machine metadata requires all metadata JSON files to follow the Solana Token Metadata Standard. You can read more about creating metadata files in Avana Wallet NFT documentation.

Prepare your files in the folder ~/cm-project/assets/. Each file should be a number, starting at 0. For our assets we will have files 0.png, 0.json, 1.png, 1.json, ... 9.png, 9.json. Each png and json file are combined to represent a single Solana NFT. For example, 0.json contains the NFT metadata for 1.png. Make sure your assets are numbered consecutively, and they do not have any gaps (for instance, 0, 1, 2, 3, 4, 5, and not 0, 1, 3, 4, 5).

Our images will be similar to this image:

Example Avana Wallet Solana NFT image to be minted using Candy Machine

Our NFT metadata will look similar to this JSON file (download JSON file example metadata.json):

Example Avana Wallet Solana NFT image metadata for Candy Machine

When you set seller_fee_basis_points, be aware that the number should be an integer and it represents basis points (1/100 of a percent), not a full percent. For example, we set the fee at 100 basis points which is equivalent to 1%. The valid number for this field is between 0 (0%) and 10000 (100%).

You can change the metadata for each NFT so it is unique to that NFT. For example, update the attributes to explain the NFT's unique properties in the description.

Metaplex has created a sample collection that you can download for testing purposes.

Step 6: Verify NFT Images & Metadata

We need to verify our assets before creating our Candy machine. Run npx ts-node ./js/packages/cli/src/candy-machine-v2-cli.ts verify_assets ./assets. The Candy Machine CLI will check the images and metadata json files.

Example of successful Candy Machine CLI verification of Solana NFT assets

Step 7: Create Your NFT Candy Machine

We are almost ready to create your Candy Machine. Verify that your keypair has funds and your NFT images and metadata are in the assets folder. Once you are ready run:

npx ts-node ./js/packages/cli/src/candy-machine-v2-cli.ts upload -e devnet -k ~/.config/solana/keypair.json -cp config.json -c example ./assets

You can change devnet to mainnet if you are using Solana mainnet.

Sample Candy Machine uploading Solana NFT assets

Step 8: Verify Upload

We can verify the upload using the Metaplex Candy Machine CLI as well:

npx ts-node ./js/packages/cli/src/candy-machine-v2-cli.ts verify_upload -e devnet -k ~/.config/solana/keypair.json -c example

The output should say ready to deploy!

Step 9: Mint Tokens

Now your Candy Machine is ready to mint Solana NFTs. The Candy Machine can only mint NFTs to users after your goLiveDate setting in config.json.

We can mint Solana NFTs from the Candy Machine CLI easily. Note that if you enabled captcha bot protection, then you will not be able to mint tokens from the command line.

npx ts-node ./js/packages/cli/src/candy-machine-v2-cli.ts mint_one_token -e devnet -k ~/.config/solana/keypair.json -c example

You can mint multiple tokens by using the command mint_multiple_tokens

npx ts-node ./js/packages/cli/src/candy-machine-v2-cli.ts mint_multiple_tokens -e devnet -k ~/.config/solana/keypair.json -c example --number 2

Sample Candy Machine successfully minted Solana NFT

We can then view the Solana NFT mint transaction on Solana Explorer. If we look at the account tokens, the NFT now shows up on the Tokens tab.

Sample Candy Machine successfully minted Solana NFT now in account

When we click on the newly-minted Solana NFT, we can see the details (if you look at link later the image may no longer exist because the file storage is temporary).

The newly-created Solana NFT shows all of the information from the metadata json file.

  • Mutable: Means that the update authority can change the on-chain metadata.
  • Collection Address: Collections are structured as NFTs. On-chain NFT collections help validate accuracy and authenticity.
  • Mint Authority: Solana address that is able to mint the NFTs.
  • Update Authority: Solana address that is able to update the NFT metadata.
Solana NFT created using Candy Machine

We can also view the on-chain metadata json created by Candy Machine. Notice that another address was added to the creators - that's normal. Also, notice that Candy Machine automatically created a Collection NFT.

Solana NFT on-chain metadata uploaded by Candy Machine

Solana Explorer parses the attributes to show them on a separate tab.

Solana NFT on-chain metadata attributes uploaded by Candy Machine

Step 10: Check Out Your Solana NFT in Avana Wallet

Avana Wallet displays your NFTs in the app. You can view all of your NFT metadata, set the NFT as your profile picture, and send the NFT to others. Read more about NFTs in Avana Wallet Docs.

Solana NFT created by Candy Machine on display in Avana Wallet
Solana NFT created by Candy Machine on display in Avana Wallet
Solana NFT created by Candy Machine on display in Avana Wallet
Solana NFT created by Candy Machine on display in Avana Wallet
Solana NFT created by Candy Machine on display in Avana Wallet


Solana NFTs
Magic Eden NFT marketplace

Upgrade your Solana wallet today


Download Avana Wallet Solana wallet for Apple iOS mobile devices. New and modern Solana non-custodial Solana wallet


Download Avana Wallet Solana wallet for Android mobile devices. New and modern Solana non-custodial Solana wallet


Download Avana Wallet Solana wallet extension for Chrome Browser. New and modern Solana non-custodial Solana wallet


Download Avana Wallet Solana wallet extension for Brave Browser. New and modern Solana non-custodial Solana wallet


Download Avana Wallet Solana wallet extension for Firefox Browser. New and modern Solana non-custodial Solana wallet


Download Avana Wallet Solana wallet extension for Edge Browser. New and modern Solana non-custodial Solana wallet


© 2022 Avana Wallet LLC