Build more with QuickNode - New pricing plans and a free tier! Read the press release

How to Deploy an NFT Collection on Solana Using Sugar (Candy Machine)

August 08, 2022

Overview

Are you ready to launch your NFT collection on Solana? Metaplex's new Candy Machine tool, Sugar, is the tool for you to launch in no time. Sugar, Metaplex's latest version of Candy Machine, comes with a few notable improvements: 
  • improved upload performance
  • simplified UX 
  • improved error handling

What You Will Do

In this guide, you will create a new wallet using Solana CLI, airdrop some SOL, and deploy a Candy Machine on Solana's devnet using Sugar. You'll then deploy your Candy Machine to the web using Candy Machine UI. 

What You Will Need

  • Nodejs installed (version 16.15 or higher)
  • Solana CLI installed
  • Phantom Wallet or Solflare extension installed 
  • Metaplex Sugar installed
  • A text editor
  • npm or yarn installed (We will be using yarn to initialize our project and install the necessary packages. Feel free to use npm instead if that’s your preferred package manager.)

Set Up Your Project

Create a new project directory in your terminal with:

set up your project

Copy
mkdir sugar-demo
cd sugar-demo

Install Sugar

Mac Installation

In your terminal enter:

bash <(curl -sSf https://sugar.metaplex.com/install.sh)

Note: You may need to restart your terminal after installation

Windows Installation


  1. Download the windows installer here.
  2. Run the installer as an Administrator (Right Click-->Run as Administrator). If you get a warning about an untrusted binary try clicking More Info and then Run Anyway. If you do not have this option, follow these steps: 
    • Right-click on the executable file and go to Properties.
    •  If you trust the Metaplex developer team, check the Unblock button as show in the image below. This will allow you to run this binary on your computer since Microsoft does not trust it automatically.
    • Click Apply and Ok.
    • Run the installer again

If all works correctly, you should see something like this:

Successful Windows Install Confirmation

Set Up a New Wallet

One of the cool new features of Sugar is that it will allow you to set your wallet and RPC configs using Solana CLI, so that you don't need to re-enter them in each of your sugar commands. 

We first need to create a new wallet for specifically devnet testing with the following command:

set up a new wallet

Copy
solana-keygen new --outfile ./wallet.json

We can skip the password (by hitting Enter) as we will only use this wallet on devnet, so the funds are not important. We can confirm that the wallet we just generated is the wallet that the Solana CLI will use by running: 

set up a new wallet

Copy
solana config set --keypair ./wallet.json

Establish a Connection to Your QuickNode RPC

Next, we will want to fund our wallet by asking for an airdrop. To do this we will need to make sure our Solana CLI is connected to a node. You're welcome to use public nodes or deploy and manage your own infrastructure, however, if you'd like 8x faster response times you can leave the heavy lifting to us. See why over 50% of projects on Solana choose QuickNode and sign up for free here.

Make sure to launch your node under the Solana Devnet and copy the HTTP link:
New Solana HTTP Endpoint

With your endpoint on the Solana Devnet setup, you can now run this command, substituting YOUR_QUICKNODE_URL with the HTTP URL you have copied:

establish a connection to your quicknode rpc

Copy
solana config set --url YOUR_QUICKNODE_URL

Now to fund your wallet you can run the command:

establish a connection to your quicknode rpc

Copy
solana airdrop 1

If the command is successful you should see something like this: 

Airdrop success

You can also run solana balance in your terminal and see that the 1 SOL is there. 

Prepare NFT Assets

If you have used Candy Machine before, this process will be familiar. We need to create a .json file corresponding to each digital asset using a simple number format starting with 0 and increase sequentially, never skipping a number (e.g., 0.json maps to 0.png, then 1.json maps to 1.png). We can also create an optional collection.json and collection.png to enable Sugar to automatically create an on-chain collection. 

Metaplex has a sample set of assets that we can download and work with to be consistent. You can edit the json to include whichever values you would like, as long as it is compliant with the URI json schema.

Download the sample set and extract the contents to ./assets/ in your project directory (this is the default directory that Sugar will look for your files). 

Configure Candy Machine

Create a new file, config.json in your root project folder: 

configure candy machine

Copy
echo > config.json

Open the file and paste this config: 

configure candy machine

Copy
{
    "price": 0.01,
    "number": 10,
    "symbol": "NB",
    "sellerFeeBasisPoints": 500,
    "gatekeeper": null,
    "solTreasuryAccount": "YOUR_WALLET_ADDRESS",
    "splTokenAccount": null,
    "splToken": null,
    "goLiveDate": "2022-07-24T00:00:00Z",
    "endSettings": null,
    "whitelistMintSettings": null,
    "hiddenSettings": null,
    "uploadMethod": "bundlr",
    "awsS3Bucket": null,
    "retainAuthority": true,
    "isMutable": true,
    "creators": [
    {
      "address": "YOUR_WALLET_ADDRESS",
      "share": 100
    }
  ]
}

NOTE: you can run solana address in your terminal to obtain the wallet address that you just created.

Now, we should be all set. If you're following along to this point you should have a directory structure like this: 

  • sugar-demo/wallet.json
  • sugar-demo/config.json
  • sugar-demo/assets/[0-9].png
  • sugar-demo/assets/[0-9].json
  • sugar-demo/assets/collection.png
  • sugar-demo/assets/collection.json

Sugar has a built in validation error that will let us check for any errors before we proceed. In terminal, run: 

configure candy machine

Copy
sugar validate

Sugar Validation Success

We're in business! Nice job. Let's build our Candy Machine. 

Create Candy Machine

Because we've set our RPC and wallet using Solana CLI and because we've saved our assets and config.json to Sugar's default directories, our commands will be quite simple! 

Upload Your Assets

In your terminal enter:

create candy machine

Copy
sugar upload

You should see something like this:
Sugar Upload Success


Deploy Candy Machine

In your terminal enter:

create candy machine

Copy
sugar deploy

You should see something like this:
Sugar Deploy Success


If you get a "Blockhash not found" error, try running the command again.

Make sure to store the Candy Machine ID provided in your terminal locally. We'll need this later.

Verify Candy Machine

Let's make sure everything has worked as we'd expected. In your terminal enter:

create candy machine

Copy
sugar verify

You should see something like this:
Candy Machine Verified

Great work!

Test Your Candy Machine

Try minting an NFT using sugar. In your terminal enter:

create candy machine

Copy
sugar mint

You should see something like this: 
Successful Sugar Mint


Excellent! Let's create a mint page so we can share this project with the world!

Set Up a Minting Site

For the easiest possible set up, we will be using the front end that Metaplex provides us, Candy Machine UI. 

From your project directory, in your terminal enter: 

set up a minting site

Copy
git clone https://github.com/metaplex-foundation/candy-machine-ui ./candy-machine-ui/
cd candy-machine-ui

Rename the file .env.example to .env. After changing the file name, you can change the values in there to the following:

set up a minting site

Copy
REACT_APP_CANDY_MACHINE_ID=<YOUR_CANDY_MACHINE_PUBKEY>
REACT_APP_SOLANA_NETWORK=devnet
REACT_APP_SOLANA_RPC_HOST=<YOUR_QUICKNODE_DEVNET_ENDPOINT>

If you don't remember your Candy Machine ID, you should be able to find it in cache.json in the program.candyMachine field. 

With all of that information plugged in, you can now save the file. From that candy-machine-ui folder, run the following commands:

set up a minting site

Copy
yarn install
yarn start

This will open up a browser at localhost:3000, where you can connect your wallet and have the ability to mint an NFT. Confirm that your Phantom Wallet is set to devnet and not mainnet before proceeding.

You'll need devnet SOL in your Phantom wallet to mint an NFT. You can use Solana CLI to airdrop to your Phantom wallet by entering this command in your terminal: 

set up a minting site

Copy
solana airdrop 1 YOUR_PHANTOM_WALLET_ADDRESS

Once you're ready, click "Mint". If done successfully, you should see a website like this:

Candy Machine Mint Page


If you see an error that says “Mint Failed”, you might not have enough funds. Try again once you’ve added funds. You can view the NFT in your wallet after purchasing. Phantom may take a moment before rendering the NFT in your wallet. Ours looks like this:

Minted NFT in Wallet


That's some sweet sugar! Nice job.

Conclusion

Congrats! You created a Candy Machine using Metaplex Sugar and have all the tools needed to run your own NFT mint. We're excited to see what NFTs you're creating! Join us on Discord or reach out to us via Twitter to share your NFT project. 

We ❤️ Feedback!

If you have any feedback or questions on this guide, let us know. We’d love to hear from you! 

Related articles 60

How to Send a Transaction On Solana Using JavaScript
Apr 13, 2022

Hello reader! Today is an exhilarating day because we are going on an expedition to the Solana Blockchain. Solana is an up-and-coming blockchain seeking to improve upon the current ecosystem's solutions to the complex problem of providing a secure, scalable, decentralized...

Continue reading
How to do a non-custodial transaction with QuickNode
Apr 12, 2022

Private keys are one of the most sensitive pieces of data when it comes to cryptography and the blockchain. However, there has always been debate/confusion about choosing between custodial wallets (where the wallet provider has custody of the user’s private key) and...

Continue reading
How to connect to Ethereum using .NET (Nethereum)
Apr 12, 2022

Dotnet or .NET is very popular for the development of desktop applications, most Windows desktop applications are built using .NET, and it also contributes largely to web application’s tech stack. In this guide, let’s see how we can connect to Ethereum using .NET and

Continue reading
How to Set Up a Near Project from Scratch
Jan 27, 2022

In this tutorial we will look at how we can setup a basic NEAR project from scratch, installing and configuring dependencies and customizing the project to work well with AssemblyScript.We will first start by initializing our project with a package.json file using...

Continue reading
Como crear y lanzar un ERC-721 (NFT)
Dec 29, 2021

Coleccionables digitales que son compatibles con ERC-721 se han vuelto muy populares desde el lanzamiento de Cryptokitties y han ganado adopción masiva en los últimos meses. Esta guía cubrirá la parte de creación y lanzamiento...

Continue reading
How to connect to Ethereum network using Java / Web3j
Apr 12, 2022

We can say that Java is one of the most versatile languages out there, and it continues to be relevant in today's time. Java is so popular because of its massive user base and use cases. In this guide/tutorial, we'll learn how to connect to the Ethereum Blockchain network...

Continue reading
How to integrate IPFS with Ethereum
Apr 12, 2022

It can be costly to store massive files on a blockchain mainnet, and this is where decentralized file storing systems like IPFS can come in handy. Sometimes, NFTs use IPFS as well. In this guide, we’ll cover how we can integrate IPFS with...

Continue reading
How to Connect to the Ethereum Network using Ruby
Jun 13, 2022

The Ruby programming language has a huge fanbase. Ruby was developed by its creator with an intention to invent a language developers can enjoy learning and using. Ruby has been largely accepted by developers all around the world since its launch, in fact, the biggest...

Continue reading
How to connect to Ethereum network with ethers.js
Apr 12, 2022

When someone thinks of developing a dApp the first tool that comes to their mind is web3.js which is pretty common because of its popularity in the community and wide use cases, dApp development has been consistently growing and there are a lot of developers who want to...

Continue reading
How to Mint an NFT on Solana
Apr 12, 2022

Updated at: April 10, 2022Welcome to another QuickNode guide on Solana - the up-and-coming blockchain that seeks to solve the scalability issues of Ethereum. We will be walking through step-by-step how to create an NFT on Solana. NFT, short for Non Fungible Token,...

Continue reading
The Web3 Developer Stack
Apr 12, 2022

A developer stack is a bag of technologies a developer possesses. For example, MEAN (MongoDB, Express.js, AngularJS/Angular, and Node.js) and MERN (MongoDB, Express.js, React, and Node.js) are common web developer stacks. Similarly, today we will learn more about the web3...

Continue reading
How to Get All Tokens Held by a Wallet in Solana
Jul 17, 2022

Hello readers! To kick off Solana Summer and the current whitelist meta, we thought it would be helpful to dig into all of the token accounts you and your users have using the getParsedProgramAccounts method. This tool is convenient for querying different...

Continue reading
How to deploy a smart contract with Brownie
Apr 12, 2022

Python is one of the most versatile programming languages; from researchers running their test models to developers using it in heavy production environments, it has use cases in every possible technical field. In today's guide, we will learn about Brownie, a Python-based...

Continue reading
Introduction to Scaffold-ETH 🏗
Dec 29, 2021

Developing applications involves juggling several moving pieces like front-ends, back-ends, and databases. But developing a decentralized application on a blockchain adds a few more elements like smart contracts and nodes that allow you to connect to the...

Continue reading
Como crear un NFT en SOLANA
Dec 29, 2021

¡Hola querido lector! Bienvenidos a una nueva guía de Solana.Solana es una blockchain que promete mucho a la hora de intentar resolver los problemas de escalabilidad que podemos apreciar en otras blockchains, como Ethereum por...

Continue reading
How to Send an EIP-1559 Transaction
Apr 12, 2022

While Ethereum has been trying to scale, it has encountered some gas price issues. Many layer 2 solutions and sidechains sprang into existence to solve this problem, but Ethereum is the main chain, and at some point, it has to be improved. EIP-1559 was introduced to...

Continue reading
How to Create an Address in Solana using JavaScript
Apr 12, 2022

Hello reader! Welcome to QuickNode's first Solana guide. Solana is an up-and-coming blockchain that seeks to solve the scalability issues that Ethereum has been handling. You will walk through step-by-step how to create a Solana address using the @solana/web3.js...

Continue reading
How to create your own DAO with Aragon
Apr 12, 2022

Blockchain provides us with the power of decentralization. Decentralization means the transfer of power to users/members rather than having a single centralized authority governing everything; it enables various use cases in finance, governance, voting, fundraising, etc....

Continue reading
How to Connect to Terra with JavaScript using Terra.js
Apr 12, 2022

Stablecoins have been bridging the gap between traditional currencies and blockchains. Stablecoins offer stable price tokens pegged by a reserve asset which is often a fiat current like USD, EUR, GBP. The Terra protocol provides a framework to work with stablecoins. This...

Continue reading
How to connect to Ethereum network using Go
Apr 12, 2022

Go helps you make faster scalable backends and this guide will show you how to connect your backend to Ethereum (and make it even faster, more reliable, and globally accessible, all thanks to QuickNode’s global infrastructure). What is...

Continue reading
How To Fork Ethereum Mainnet with Hardhat
Apr 12, 2022

Forking the chain at an older block of the blockchain is helpful if you want to simulate the blockchain’s state at that block; Hardhat has this functionality built in. In this guide, let’s go through the process of forking the Ethereum Mainnet at an older...

Continue reading
How to connect to Ethereum using PHP
Apr 12, 2022

PHP is a very popular choice among developers and has a vast community due to its long presence in web development. In this guide, we’ll cover how to connect to Ethereum with PHP using the web3.php...

Continue reading
How to use Subspace with QuickNode
Apr 12, 2022

In this guide, we'll understand a bit about reactive development and how to use Subspace with QuickNode.JavaScript is the programming language behind most of the internet apps and websites. JavaScript today has become one of the most used programming languages,...

Continue reading
How to Connect Your Dapp With MetaMask Using Ethers.js
Dec 29, 2021

In our dApp, we will have a simple react user interface that has a material button asking the user to connect to MetaMask. And if they do not have an account, they can create one or log in to their account. They will then view their wallet balance and address displayed on...

Continue reading
How to generate a new Ethereum address in Go
Dec 29, 2021

Golang is very popular among backend developers for building infrastructures and microservices. Go is a procedural programming language. Developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google, then launched in 2009 as...

Continue reading
How to generate a new Ethereum address in Python
Dec 29, 2021

Python is one of the most versatile programming languages out there with an abundance of use cases; We can build many applications with Python from client-side to back end. In this guide, we will cover creating an Ethereum address in Python using the

Continue reading
How to Get Transaction Logs on Solana
Jul 11, 2022

Ever need to pull all the transactions associated with a Wallet? Want to see all of the mint transactions associated with a Candy Machine? Or maybe see transaction history of an NFT? Solana's getSignaturesForAddress method is a versatile tool that makes...

Continue reading
How to Lazy Mint an NFT on Rarible with Rarepress
Apr 12, 2022

NFTs are great for creators to monetize their artwork and for people to get ownership of an item. But since gas prices are usually high given the highly in-demand space on Ethereum, minting an NFT or an NFT collection can become costly for a creator. Lazy minting solves...

Continue reading