Create Nft using candymachine

Joel varghese
4 min readOct 8, 2023

--

We’ll learn how to mint a collection of NFTs. We’ll do this using Candy Machine — It’s a program that lets creators bring a collection of assets on chain easily. It’s the standard and easiest way to deploy multiple nfts on Solana ecosystem. This is how real word artists ship their projects like Trippin Ape Tribe, Akari, and Sea Shanties.

Since the program runs on the Solana, everything is kept in accounts. You begin by setting up a Candy Machine instance in your collection. That’s merely an account that will save some crucial owner information and your Candy Machine’s setup in a metadata field.

Install the CLIs

Before we can get into this, we’ll need to install:

  1. The Solana CLI — the Sugar CLI needs this. You can install it here for your OS.
  2. The Sugar CLI — you can install it here.

Note — If you want to keep CLI installs separate from your machine, you can set up the Solana CLI on Docker and then download the Sugar CLI. Docker image here. If you don’t know what Docker is, don’t worry about this!

If they were installed right, you should see version numbers instead of errors when you run solana --version and sugar --version in your terminal.

This is also a good time to set up your local Solana wallet on the devnet if you don’t have one. Run these commands in your terminal:

solana config set --url devnet
solana-keygen new --outfile ~/.config/solana/devnet.json
solana airdrop 2
solana balance

Set up your collection

This is going to be one of the hardest parts of the build: deciding what you want to make an NFT collection of. You’ll need at least 5 images, one for each NFT in your collection. I’m going with some dog images because i love dogs ❤

Make a new project folder in your Solana workspace and create an assets folder inside it.

mkdir sugar-cm-demo
cd sugar-cm-demo
mkdir assets

You need to pair each NFT asset with a metadata JSON file, numbering each pair from zero with an additional collections.pngand collections.json pair for thumbnail of the collection. So, your folder structure should look something like this:

...
|
|── assets
| |── 0.png
| |── 0.json
| |...
| |── 5.png
| |── 5.json
| ├── collection.png
| └── collection.json
|
....

The JSON file will be like this. This is the format made by metaplex. You can use this or download the assets file directly from metaplex.

{
"name": "Number #0001",
"symbol": "NB",
"description": "Collection of 10 numbers on the blockchain. This is the number 1/10.",
"image": "0.png",
"attributes": [
{
"trait_type": "Number",
"value": "0"
}
],
"properties": {
"files": [
{
"uri": "0.png",
"type": "image/png"
}
]
}
}

Launch your NFT collection

Now you’ll be left with a config.json file in your project folder. You can use this template:

{
"number": 10,
"symbol": "NB",
"sellerFeeBasisPoints": 500,
"isMutable": true,
"isSequential": false,
"ruleSet": null,
"creators": [
{
"address": "YOUR_WALLET_ADDRESS",
"share": 100
}
],
"uploadMethod": "bundlr",
"awsS3Bucket": null,
"retainAuthority": true,
"awsConfig": null,
"nftStorageAuthToken": null,
"shdwStorageAccount": null,
"pinataConfig": null,
"hiddenSettings": null,
"guards": {
"default": {
"solPayment": {
"value": 0.01,
"destination": "YOUR_WALLET_ADDRESS"
},
"startDate": {
"date": "2022-10-23T20:00:00Z"
}
}
}
}

These are the some important things you should know

  • number: It’s number of nft in our collections
  • symbol: The symbol of our NFT (eg. DOG)
  • sellerFeeBasisPoints: This the royalty the creator recieves when the nft is sold (550 means 5.0% royalties)
  • creators: This the list of creators for the collection (In our case there is only one)
  • uploadMethod: There are different upload services like aws and bundlr (We use bundlr because it is decentralised)
  • retainAuthority: We have enable this attribute if we have to retain the authority make future changes in the collection.
  • guards: By default candymachine V3 doesn’t allow anyone other than than creator to mint the nfts. Guard is in place to set criteria for users to mint the nft.

Now we can check errors and and deploy our assets.

#check for errors in the folder
sugar validate

#uploads the images
sugar upload

#deploys the assets
sugar deploy

#verifies that everything has worked as we expected
sugar verify

Now we have successfully uploaded the nft and now we can add the guard and mint the nft.

sugar guard add
sugar mint

Hope this was informative :)

I’ll be writing another tutorial on how to create a frontend to mint the nft you created, so you can view it in your wallet like this:

--

--