Creating and Deploying a Solana NFT Collection Using a Candy Machine — My First Experience Working With Solana

Miguel Canas
Coinmonks
9 min readMar 3, 2024

--

In recent years, as the use of blockchain has spread, the popularity of NFTs has also grown exponentially.

From UkraineDAO, a project that raised over $9.5 million by selling NFTs of the Ukrainian flag, to Decentraland, a metaverse world where users sell and buy plots of land represented by NFTs, every day brings new ways to take advantage of this technology.

To better understand how these assets are created and transacted, I deployed my collection of NFTs on the Solana blockchain. However, before I go on to explain how I developed this collection of NFTs, let’s break down what is an NFT and what’s different about creating an NFT in the Solana blockchain compared to using other blockchains such as Ethereum (aka the most popular blockchain out there).

What is a NFT?

NFT stands for Non-Fungible Token and is a token characterized by its immutability. To ensure the accomplishment of this immutability property, no other NFT can be created using the same metadata (unique properties registered on blockchain for each NFT).

Due to their digital nature, NFTs are mainly used as proofs of ownership of digital assets such as images (the default NFT), documents, or music. However, although less common, some projects use NFTs to attest to the ownership of physical assets such as land parcels or houses.

The process by which the metadata of a physical or digital asset is recorded on the blockchain is called minting and involves paying a fee to the validators as a reward for the amount of cryptocurrency that the validator staked to validate the process (this only refers for blockchains that operate based on a proof of work protocol). Sometimes, in less technical scenarios, the minting process is also referred to as tokenization.

Particularities of Solana

From the beginning of my involvement with blockchain, I saw Solana as the blockchain with the most potential. When some friends ask “Why Solana?” I always reply “Even though Solana isn’t the future of blockchain it is the closest blockchain to this future”. And if I believe on this, it’s because of the unique protocol Solana operates on, the proof of history (PoH).

PoH is a protocol that consists of a proof of stake in which all transactions recorded on the blockchain are recorded with an implicit timestamp. Solana therefore achieves much faster and cheaper transactions (lower transaction fees) when compared to blockchains that use proof of stake in its original version. In proof of stake, the validators involved in validating the transaction will have to validate the moment it was made. In proof of history, although the validators still have to validate the transaction itself, the order in which the transactions take place becomes a no-brainer for the validators, thus allowing for less communication between nodes and faster transaction validation.

So, given the energy efficiency (a Solana transaction consumes 60% of the energy of a Google search!) of PoH and the growing ecosystem of services integrated into Solana, I decided to create my first NFT collection in Solana.

Creating my Solana NFT Collection

  1. Which assets to mint?

First of all, I knew I wanted to create something that, even though it had little impact on the world and the blockchain universe, had some kind of personal meaning for me. So I decided to create a collection of NFTs called “A Taste of India”, which includes some of the moments I’ve experienced living in India over the last six months.

A photo of the sunrise in the village of Khubawali taken by me and one of the NFTs of the collection

2. Looking for a good tutorial!

Knowing the assets I wanted to use to create my collection of NFTs, I started looking for a tutorial that would help me realize this project. After a few days of searching and being disappointed by the simplicity and complexity of a dozen other tutorials, I finally found a tutorial on the QuickNode website, a node provider for a large number of blockchains, including Solana.

3. Setting the development environment

To create this NFT collection I needed five tools: node.js (a tool used to execute JavaScript code outside of a web browser), Solana CLI (Solana command-line interface so we can develop in Solana on the command prompt), a phantom wallet (wallet compatible with Solana), yarn (a common javascript package manager) and Metaplex.

Metaplex is a toolkit (including a default smart contract and some other standards for building and managing NFTs on the Solana blockchain) widely used to create tokens and NFTs on the Solana blockchain that I also used to create this NFT collection. Creating a customized smart contract on Solana is much more complex than on blockchains like Ethereum since Solana uses parallel processing (simultaneous recording of multiple transactions on the blockchain). That’s the reason why tools such as Metaplex are so popular among Solana developers.

4. Setting the project directory and a devnet wallet

Having settled the developing environment, I needed to create a directory in my computer called sugar-demo, inserting the following in my command prompt.

mkdir sugar-demo
cd sugar demo

After this step, I inserted the instructions below in my Command Prompt to create a Solana wallet. Since this is a project only implemented on the realm of devnet (basically a project not registered in the official Solana blockchain), I didn’t establish a bip39 passphrase (mnemonic seed phrase widely used in the world of crypto) for the wallet as an extra layer of security.

solana-keygen new --no-bip39-passphrase --outfile ./wallet.json
solana config set --keypair ./wallet.json

That created a wallet.json file (a JSON file is a file written following the javascript standards but not necessarily being part of a javascript program) with the private key of the wallet just created within the sugar-demo directory. The private key is the only way I can use to prove the ownership of my wallet and thus move the funds within it (contrasting with the public key, the public address for which different users can send me funds).

5. Connecting to a node and getting funds for the wallet

To insert this project into Solana devnet, it was necessary to connect it to a Solana API endpoint, basically a gateway that allows the wallet created and the NFTs stored in it to be inserted into the circuit of validators that operate on the Solana blockchain. To carry out this process, I inserted the instructions below with a link that established a connection with a Solana API Endpoint that I created in QuickNode (other options for this service could have been Alchemy or RunNode).

solana config set --url My_Solana_Endpoint_URL

Once the wallet’s integration into Solana’s node network had been established, it was time to allocate sufficient funds to my wallet to cover the transaction fees resulting from the minting of the NFT collection I was creating. To do this, I entered the code below into the Command Prompt.

solana airdrop 1

I now have 1 SOL available in my wallet. As for this specific step, it’s worth mentioning a constraint I felt: first of all, there’s a limit of 24 daily SOLs that can be generated on the same computer and when they’re exceeded, as unfortunately happened to me :((, it forces you to wait until the next day to make a new airdrop. Btw, unlike a mainnet SOL token, a devnet SOL token has no real value — yeah I also got sad when I realized this wasn’t a way to generate free money.

6. Establishing the metadata

Having established a connection to an endpoint, I then created a sub-directory called “assets” into which I inserted the 10 images I wanted to tokenize. For each one, I created a JSON file containing the metadata for each one, according to the following structure.

{
"name": "First Photo",
"symbol": "PTIN",
"description": "Collection of 10 photos from the months I'm living in rural Maharashtra on the blockchain. This is the photo number one.",
"image": "0.jpg",
"attributes": [
{
"trait_type": "Image",
"value": "0",
"date created": "2023-08-29",
"creator": "Miguel Canas",
"tags": ["photo", "travelling", "India"],
"provenance": "Verified authentic",
"supply limit": 1,
"rights_holder": "Miguel Canas",
"blockchain_platform": "Solana"
}
],
"properties": {
"files": [
{
"uri": "0.jpg",
"type": "image/jpeg"
}
]
}
}

Even though the attributes remained the same for all of the NFTs of the collection, I changed their values according to each asset. I spent some time on this step to ensure that I established a certain degree of specificity in the metadata for each of the NFTs in this collection, ensuring the uniqueness of the metadata for each of the NFTs in this collection. Among the different attributes listed, it is important to highlight the explicit reference to the file’s name to which the metadata created corresponds, which is fundamental if the NFT is to fulfill its primary function of proof of ownership.

Deploying the Candy Machine

  1. What is a Candy Machine?

The Candy Machine is the default smart contract included in the set of tools covered by Metaplex and is specially designed to ensure a fair and efficient distribution of the NFTs that make use of it. Bearing in mind the complexity of Solana smart contracts and the low complexity of the tokenization process for the assets involved in this project, I chose to use this tool, creating the following JSON file (config.json file) in the project directory to establish the conditions under which the Candy Machine would be used.

{
"number": 10,
"symbol": "PTIN",
"sellerFeeBasisPoints": 500,
"isMutable": true,
"isSequential": false,
"ruleSet": null,
"creators": [
{
"address": "B7SaXHaYJuU5NeZk3V3zCvJ5XHNY3vcjx5APUSgx4kcb",
"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": "B7SaXHaYJuU5NeZk3V3zCvJ5XHNY3vcjx5APUSgx4kcb"
},
"startDate": {
"date": "2022-10-23T20:00:00Z"
}
}
}
}

From the code presented above, it is important to highlight the definition of uploadMethod as bundlr, since it is through this Arweave-based technology that the images associated with each of the NFTs are stored.

2. Deploying the Candy Machine

sugar upload
sugar deploy

Once you have established the conditions for minting the NFTs in the previous point, enter these instructions into the Command Prompt. Boom, I had finally created my Candy Machine, and my collection of NFTs was ready to be minted!

3. Testing the Candy Machine and Adding the Candy Guards

sugar mint

To see if the deployed candy machine was fully operational, I decided to mint an NFT from this collection, adding the ninth photo to my wallet as you can see in the image below.

My Devnet Solana Wallet overview
sugar guard add

Finally, I’ve inserted the above instructions to ensure that the minting conditions defined in the config.json file can be accessed by any user and not just me as the creator of the collection (it might help to think of the sugar guard as a security mechanism for minting NFTs).

Check the full operational Candy Machine here

Check all the files used to deploy this Candy Machine here

Final Thoughts + Future of NFTs

As my first project at Solana, creating this collection of NFTs helped me to develop a practical application of the concepts I had already been delving into over the last few months from a more theoretical perspective (minting, tokenization, etc.).

Today, after creating this collection of NFTs, I do not doubt that this is a technology that will have a tremendous impact on the world, namely in unlocking new forms of financing for artistic production and creating a new dimension for the practice of patronage (for example, Empowa project is using NFTs to finance the construction of climate-smart housing in Mozambique → check more about them here).

However, despite this tremendous potential, NFTs have a deep vulnerability: the possibility of multiple NFTs being created based on the same asset, thus invalidating their function as proof of ownership. The existence of an NFT used to attest to the ownership of an asset does not prevent another NFT from being created on the same blockchain claiming ownership of the same asset but with slightly altered metadata, or another NFT from being created on a different blockchain claiming ownership of the same asset and with the same metadata. The development of interoperability solutions between blockchains, along with the detection of similarities in the metadata of NFTs within each blockchain, are possible solutions to this problem.

The splendor of this technology is irrefutable, but as long as these vulnerabilities persist, the use of NFTs as proof of ownership will always be limited to a small set of potential applications. In future projects, I hope to have the opportunity to delve into the minutiae of how NFTs work and to contribute to their development!

See you next time

Best ✌️

--

--

Miguel Canas
Coinmonks

I'm a 17 y/o from Lisbon exploring Solana and how to use it to bank the unbanked. The financial system has failed, it's time to embrace blockchain.