Blog
Easy Guide To Mint Solana NFTs Using Candy Machine V2
5/23/2022
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:
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.
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:
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.
First, let's get started by installing all of the software packages we will need to mint Solana NFTs with Candy Machine:
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
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 https://github.com/metaplex-foundation/metaplex.git .
- 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
.
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.
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]
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.
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 https://api.devnet.solana.com/
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 https://solfaucet.com.
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:
Your Wallet Address
with the address from Step 3.
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
.
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:
Our NFT metadata will look similar to this JSON file (download JSON file example metadata.json):
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.
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.
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.
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!
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
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.
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.
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 Explorer parses the attributes to show them on a separate tab.
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.
Upgrade your Solana wallet today
Download
iOS
Android
Chrome
Brave
Firefox
Edge