My First Candy Machine
This guide is for Candy Machine v2. You might want to follow the more up to date guide for Candy Machine v3.
The goal of this tutorial is to take you from zero to one: you will learn to install Sugar and use its basic commands to configure and deploy a candy machine to Solana's devnet. It will provide you with a foothold on the basics and enough knowledge that you can then use the rest of the developer resources to learn the more advanced details for using Sugar.
- You should have a basic understanding of how to find and use a terminal on your OS, including navigating directories, and running commands: an example of a terminal for macOS is iTerm2.
- You should have basic familiarity with what Solana is but don't need advanced technical knowledge.
- You should have basic familiarity with the Metaplex Standard but, again, do not need advanced technical knowledge.
This tutorial targets macOS, Linux, and Windows Subsystem Linux (WSL), but all commands and screenshots are from a macOS system. It should work on any of those three systems. For installing on Windows see the Windows method on the installation page.
Install the Solana CLI Tool Suite
The Solana CLI Tool Suite is useful to have for Solana development, and we will use the config file to store our keypair file path and RPC node url to simplify the Sugar commands we run, by eliding those options.
To install, follow this guide to install the Solana Tool Suite and set up a devnet wallet.
Once finished, come back here to resume the tutorial.
To install Sugar, simply copy and paste and run this command in your terminal:
bash <(curl -sSf https://sugar.metaplex.com/install.sh)
This will download and run an install script from the Metaplex Sugar repo. The install script checks your OS and downloads the correct binary for it and installs it on your system PATH, so you can run the Sugar command from any directory on your system.
Follow any instructions from the install script regarding updating your PATH. This may require closing and reopening your terminal. Once complete you should be able to run the command
sugar in your terminal and get a list of available commands:
Command line tool for creating and managing Metaplex Candy Machines.
sugar [OPTIONS] <SUBCOMMAND>
-h, --help Print help information
-l, --log-level <LOG_LEVEL> Log level: trace, debug, info, warn, error, off
-V, --version Print version information
bundlr Interact with the bundlr network
collection Manage the collection on the candy machine
create-config Interactive process to create the config file
deploy Deploy cache items into candy machine config on-chain
freeze Commands for the Candy Machine Freeze feature
hash Generate hash of cache file for hidden settings
help Print this message or the help of the given subcommand(s)
launch Create a candy machine deployment from assets
mint Mint one NFT from candy machine
reveal Reveal the NFTs from a hidden settings candy machine
show Show the on-chain config of an existing candy machine
sign Sign one or all NFTs from candy machine
thaw Thaw an NFT or all NFTs in a candy machine
unfreeze-funds Unlock treasury funds after freeze is turned off or expires
update Update the candy machine config on-chain
upload Upload assets to storage and creates the cache config
validate Validate JSON metadata files
verify Verify uploaded data
withdraw Withdraw funds from candy machine account closing it
Set Up Your Project
Next we are going to set up a simple project directory with some example assets which you can download from here. Extract the zip file and rename the folder to 'assets'.
Create a folder for your project somewhere convenient on your OS. For this tutorial we are creating a folder called MyProject on the Desktop. Next, copy the "assets" folder you downloaded into this folder so your project directory looks like the following:
. . .
We will run all our Sugar commands from within the project directory and Sugar will create our config and cache files in that directory. If we do this, we can elide the cache and config files from our commands as Sugar will look in the current directory for
Create a Config File
The config file tells Sugar how to configure your candy machine with values such as number of assets, what creators to use, what settings to apply, etc. To create a config file we are going to use the Sugar
create-config interactive command.
Run the following command in your terminal from within your project directory:
We will now get a series of questions we need to answer to set up our config file.
? What is the price of each NFT? ›
This is the price we wish to charge for selling each of our NFTs. The price is either in SOL or in an SPL token we specify. For this tutorial we are just setting up a basic candy machine that charges users in SOL. Input your desired price and then press "enter" to go to the next step. Decimal values such as
1.33 are ok.
? Found 10 file pairs in "assets". Is this how many NFTs you will have in your candy machine? (y/n) ›
This is the number of NFTs we are configuring our candy machine to mint and must match the number of asset pairs we have in our
assets directory. In this case, Sugar has detected we have 10 asset files pairs, so we can simply input
y to confirm this is correct.
? Found symbol "TEST" in your metadata file. Is this value correct? (y/n) ›
Sugar has detected the symbol for our NFT from our assets files so once again we can just input
y to confirm this is correct.
? What is the seller fee basis points? ›
The seller fee basis points is the amount of royalty we want to charge on secondary sales (all sales after the candy machine minting). Basis points are percentage times 100, so e.g. 500 basis points is 5%, and 150 is 1.5%. Input the value you wish to use for this and press "enter" to go to the next step.
? What is your go live date? Enter it this format, YYYY-MM-DD HH:MM:SS [+/-]UTC-OFFSET or type 'now' for current time. For example 2022-05-02 18:00:00 +0000 for May 2, 2022 18:00:00 UTC. ›
The candy machine "go live date" is when the candy machine becomes active and minting from it is allowed. We can either input a date here in the format specified or we can input "now" for the current time. Input "now" and hit enter to go to the next step.
? How many creator wallets do you have? (max limit of 4) ›
Here we enter the number of creators who are part of this project and who we want to receive royalties from secondary sales. For this tutorial we will use one creator so input "1" and press enter.
? Enter creator wallet address #1 ›
Now we need to provide the Solana wallet address for each creator. In this case, we only have one creator, and we are going to use our own address for that creator, so we can run
solana address in a separate terminal window to retrieve the address of the wallet we configured in a previous step. Input this value and press enter.
? Enter royalty percentage share for creator #1 (e.g., 70). Total shares must add to 100. ›
We only have a single creator, so we put in
? Which extra features do you want to use? (use [SPACEBAR] to select options you want and hit [ENTER] when done) ›
✔ SPL Token Mint
✔ Whitelist Mint
✔ End Settings
✔ Hidden Settings
✔ Freeze Settings
This step allows us to configure advanced settings for our candy machine, but we are not using any of them in this tutorial, so we simply press [Enter] to continue on.
? What is your SOL treasury address? ›
Once again we will use the address of our keypair set in the Solana config in a previous step. If you have it handy you can enter it here, otherwise, you can run
solana address again in a separate window to retrieve it.
? What upload method do you want to use? ›
This lets us choose which method we are using to store our off-chain NFT metadata (the images and data in the .json files for our assets). The simplest one to start with is
Bundlr as it does not require any extra configuration other than having a funded Solana address. Bundlr will upload our metadata and images to Arweave, a blockchain designed for permanent and decentralized data storage.
Use the [SPACEBAR] to select the Bundlr option.
? Do you want to retain update authority on your NFTs? We HIGHLY recommend you choose yes. (y/n) ›
This is an advanced setting and lets us give away update authority to the owner of each NFT individually, but we do not recommend doing this initially as it will prevent you from fixing any mistakes you make in your candy machine after NFTs are minted. Select
yes for this case by inputting
? Do you want your NFTs to remain mutable? We HIGHLY recommend you choose yes. (y/n) ›
Similarly, we recommend leaving your NFTs as mutable so you, the update authority, can fix any issues post-mint. You can always set your NFTs to be immutable later using a third-party tool such as Metaboss, but this is a one way street: once set immutable, you can never make them mutable again. Input
y to select yes and leave your NFTs mutable.
If all steps were followed correctly you should now see:
[2/2] 📝 Saving config file
Saving config to file: "config.json"
Successfully generated the config file. 🎉
✅ Command successful.
Open up the generated file, config.json, in your favorite text or code editor (e.g. VS Code). You should see a file similar to this:
"goLiveDate": "11 Aug 2022 18:19:16 +0000",
Your values will be different depending on and what you input for various settings.
Upload Images and Metadata to External Storage
In this step, we will upload all our assets file pairs to Arweave via Bundlr.
Solana is designed to be a high-throughput, low-latency blockchain that can host smart contracts, but one of the design tradeoffs is that storing data on Solana is fairly expensive. For NFTs, we only store basic information about the NFT, such as the name, symbol, creators, and seller fee basis points. For the image and all the other metadata, we have a URL on-chain on Solana that points to an external JSON file containing all that information.
This URL can point to any JSON file anywhere. It can be a decentralized file storage blockchain like Arweave or Filecoin, a peer-to-peer distributed file system like IPFS, or even a centralized cloud server like AWS.
Sugar currently supports four upload methods: Arweave via Bundlr, IPFS via NFT Storage, Shadow Drive and AWS.
In our previous step we selected
Bundlr as our upload method, and we saw this in the config file when we viewed it. Now, all we have to do is run the following command:
[1/4] 🗂 Loading assets
Found 10 asset pair(s), uploading files:
| images | 10 |
| metadata | 10 |
[2/4] 🖥 Initializing upload
-> pubkey: PanbgtcTiZ2PveV96t2FHSffiLHXXjMuhvoabUUKKm8
-> lamports: 5939049 (◎ 0.005939049)
[3/4] 📤 Uploading image files
Sending data: (Ctrl+C to abort)
[00:00:09] Upload successful ██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 10/10
[4/4] 📤 Uploading metadata files
Sending data: (Ctrl+C to abort)
[00:00:00] Upload successful ██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 10/10
10/10 asset pair(s) uploaded.
✅ Command successful.
Sugar commands are designed to be robust and commands such as
deploy will pick up where they left off when you run them again. You may occasionally get an error such as:
🛑 Error running command (re-run needed): Blockhash not found
In such cases it's safe to rerun the command until it succeeds.
However, some upload methods such as Bundlr, do cost funds to upload and store the data. If you successfully upload your data and then run it again, it will charge you again. If you do this repeatedly with a large amount of data it can cost you a significant amount of SOL. Once you have successfully uploaded your data you should not have to do it again, as the cache file will store all the links to the data. Ask on the Metaplex Discord if you run into any unexpected issues.
When uploading is finished, sugar will have created a
cache.json file in our project directory. Open this file, and you will see something similar to:
"name": "Studious Crab #1",
"name": "Studious Crab #2",
"name": "Studious Crab #3",
"name": "Studious Crab #4",
"name": "Studious Crab #5",
"name": "Studious Crab #6",
"name": "Studious Crab #7",
"name": "Studious Crab #8",
"name": "Studious Crab #9",
"name": "Studious Crab #10",
Each asset from our
assets directory has been uploaded to Arweave and a link to it stored in the cache file. You can open one of these links in the browser to see what this looks like. Within the data in the metadata link, there is another link to the image. Both of these links are stored for each item in the cache file.
If you look at the candy machine values at the top, you'll see they are empty because we have not actually created a candy machine yet. We will do that next.
Deploy a Candy Machine
To create and deploy a candy machine, run the
[1/2] 🍬 Creating candy machine Candy machine ID: Ews3L5NoAjjLEHYqEu47DqQ77nsqgNQs3NuELjBCd5bb
[2/2] 📝 Writing config lines Sending config line(s) in 1 transaction(s): (Ctrl+C to abort) [00:00:03] Write config lines successful ████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 1/1
✅ Command successful.
Once this finishes, if you open up the cache.json file again you will see that the candy machine values have been filled in as we now have a candy machine created on-chain.
Verify Successful Deployment
Once the deployment finishes, we can verify successful deployment with:
[2/2] 📝 Verification Verifying 10 config line(s): (Ctrl+C to abort) [00:00:01] Config line verification successful ████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 10/10
Verification successful. You're good to go!
See your candy machine at: -> https://www.solaneyes.com/address/Ews3L5NoAjjLEHYqEu47DqQ77nsqgNQs3NuELjBCd5bb?cluster=devnet
✅ Command successful.
Our candy machine is now successfully deployed!
Mint a NFT
Finally, to round off this tutorial we will mint an NFT from our candy machine to ensure it works as expected. Run:
to mint one NFT to your wallet address.
[1/2] 🔍 Loading candy machine Candy machine ID: Ews3L5NoAjjLEHYqEu47DqQ77nsqgNQs3NuELjBCd5bb ▪▪▪▪▪ Done
[2/2] 🍬 Minting from candy machine
Minting to PanbgtcTiZ2PveV96t2FHSffiLHXXjMuhvoabUUKKm8 ▪▪▪▪▪ Signature: jAUVJv4ezyumvKYWvuEsMcDtWRujCK4xFL9q8MCe7PmDiVuAGHNY5PFGKUH5hY4PnqtGMyvDjX821xxCiGAChzQ
✅ Command successful.
Now you can open your wallet in an explorer like Solana Explorer and view the NFT you just minted by clicking on the "Tokens" tab.
To set up a front end to allow users to mint from your candy machine, see the Mint UI Guide
Congratulations! You have successfully configured, created, and deployed your first candy machine!