Blockchain, CandyMachine, NFT, NFTs, Non-fungible Token, Solana

How to Mint NFTs with Solana’s CandyMachine

nft-ga4a6123a8_640

In this blog post, we will provide a useful step-by-step tutorial on how to create some NFT’s and mint them using the Candy Machine protocol, created by Metaplex.

To get started, we must install the following dependencies to create your NFT’s:

Once installed, we must then install the Phantom Wallet extension. If you are familiar with Metamask, Phantom is similar but used for Solana’s network. After installing the wallet, you must create an account and save the 12-word seed in a secure location.

Once in the wallet, we must change Solana’s Mainnet to Devnet. This is because to operate in Mainnet, we would need to spend some Sol’s. But, in Devnet, we can fund our wallet with some fictional Sol’s (these have no value, so using them will have no effect, nice try though).  

To do this, go to settings, as the image above shows, and scroll down until you see the following: 

Then, select the Devnet option. FYI – you will need to send some Sol to your phantom address to avoid problems when we are ready to Mint. You can get Sol’s to do this from the following faucet

You are now ready to start coding. To get started, go to the following repository and clone it. Before we interact with the cloned repository, we first need to do some configurations using the Solana CLI. We need to open a terminal to start interacting.

(I highly recommend having a document to save important information for interacting with Solana’s CLI, and later with the Candy Machine Protocol.)

First we are going to configure the URL in order to work on the devnet or in the mainnet, in this tutorial we are going to use the devnet.

The command for this is: $ solana config set — URL https://api.devnet.solana.com

If you want to be on the mainnet: $ solana config set –URL https://api.mainnet-beta.solana.com

The terminal should then respond with something like:

Config File: /Users/tomasvelasquezrestrepo/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com 
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/tomasvelasquezrestrepo/.config/solana/devnet.json 
Commitment: confirmed 
MacBook-Pro-de-Tomas:js tomasvelasquezrestrepo$

With the same command ($ solana config set) you can also get the configuration settings. 

The next step is to create a wallet for this project using: $ solana-keygen newoutfile ~/.config/solana/devnet.json

This should return the following:

Wrote new keypair to /Users/tomasvelasquezrestrepo/config/solana/devnet.json

============================================================================

pubkey: EqYkTTEe4z342BKH6wn2FCYgyhoiNZri6RgAzUrMw2Eg

============================================================================

Save this seed phrase and your BIP39 passphrase to recover your new keypair:

YOU SHOULD NEVER SHARE YOUR 12 WORD SEED

============================================================================

(Remember to save the public key and the seed in your important document.)

Next up, you will need to set the recently created keygen as default, we should throw: $ solana config set –keypair ~/.config/solana/devnet.json

We will then receive something like this:

Config File: /Users/tomasvelasquezrestrepo/.config/solana/cli/config.yml

RPC URL: https://api.devnet.solana.com 

WebSocket URL: wss://api.devnet.solana.com/ (computed)

Keypair Path: /Users/tomasvelasquezrestrepo/.config/solana/devnet.json 

For testing that this address set is seated up as the default one, we can check its balance using:

  • $ solana balance, which should respond with 0.

With this command, we are going to magically airdrop some funds in our address:

  • $ solana airdrop 5, which should respond with the following:

Signature: 2y7p5wchXuyGtKPHCEchTJ63dU6PKuvMFdoVCwiELAsHCG6Zx3fZDbn3PyGn4X9THmCpevS7j6VDmdVtebAAZFyv

5 SOL:

If you are asked again for your address, it should have changed to 5.

Time to create your NFTs

You must move to the metaplex directory (the repository we cloned before), and once you are there, you must create a new folder and name it Assets. From there, you will import 3 images (from google or anywhere), and name them as:

  • 0.png
  • 1.png

Then you must create the metadata for those images:

  • 0.json
  • 1.json

The structure should look like this:

You must create the metadata using the Metaplex standard. In this example, I’m creating an NFT for the character Rick Sanchez from Rick and Morty. The struct from my JSON file is the next one up:

Here is the accompanying image:

In the JSON file, in “address” you must copy and paste your Phantom address. Also, the “seller_fee_basis_points” is where you can establish the royalties percentage awarded to the creators of the images in question. 

After creating our NFTs, we should move to – $ cd metaplex/js. Then, in the terminal we should throw:

  • $ yarn install
  • $ yarn build
  • $ yarn bootstrap

Now, we are ready to upload our NFTs. If we are standing on the metaplex directory we should type: 

$  ts-node js/packages/cli/src/candy-machine-cli.ts upload ./assets –env devnet –keypair ~/.config/solana/devnet-test.json 

The terminal should then throw something like this:

Beginning the upload for 2 (png+json) pairs

started at: 1634576261129

wallet public key: CoefQaELYn1NHxW4ncPG8S9b28m29rCDcmKwbEwexZeV

Processing file: 0

initializing config

initialized config for a candy machine with publickey: 6ngLWVih575JqcoUuAH8yBjbCzi6HhHXDb1XqNRYAaFd

Writing indices 0-1

Done. Successful = true.

ended at: 2021-10-18T16:58:21.524Z. time taken: 00:00:40

Here, we should save (in our important information document) the candy machine with its public key. In VSDC, we can see that a new folder named .cache is created where there is a file named devnet-temp. We should save the info of this file in our document.

Now we are ready to create the Candy Machine! Also, with this command we are going to set a price for the minting:

$ ts-node js/packages/cli/src/candy-machine-cli.ts create_candy_machine –env devnet –keypair ~/.config/solana/devnet-test.json –price 1

The response should look like this: 

wallet public key: CoefQaELYn1NHxW4ncPG8S9b28m29rCDcmKwbEwexZeVcreate_candy_machine finished. candy machine pubkey: J8of4TNnDhukY6JuhEVUHk52mUrDinFAqM5HggRTkf2q

You should also save the candy machine pubkey (notice that this address is different from the candy machine with the public key address that we saved before). The next step is putting a date so the candy machine can mint the NFTs. To do this, use the following command:

$ ts-node js/packages/cli/src/candy-machine-cli.ts update_candy_machine –env devnet –keypair ~/.config/solana/devnet-test.json –date “18 Oct 2021 14:15:00 GMT-3”

The response should be:

wallet public key: CoefQaELYn1NHxW4ncPG8S9b28m29rCDcmKwbEwexZeV – updated startDate timestamp: 1634577300 (18 Oct 2021 14:15:00 GMT-3) update_candy_machine finished uQmKistJkWQNdBeCmBApSMTqbyMdD66AkQxkKpEFqg5a8qHKMRyGCHJWUaTD8mRnawR8sdp5M3k5DUvGt7Vzqaf

(You should also save the timestamp in your important info document)

The next step will be cloning the following repository: We should open it in our terminal with:

  • $ yarn install
  • $ yarn build

Then, standing in the candy-machine-mint directory, we should rename the file .env.example to .env. And then, in that file, we should change the environment variables:

  • REACT_APP_CANDY_MACHINE_CONFIG= use the candy machine with pubkey address
  • REACT_APP_CANDY_MACHINE_ID= use the candy machine pub address
  • REACT_APP_TREASURY_ADDRESS= use the publickey we generate with solana cli
  • REACT_APP_CANDY_START_DATE= use the timestamp
  • REACT_APP_SOLANA_NETWORK= devnet
  • REACT_APP_SOLANA_RPC_HOS = https://explorer-api.devnet.solana.com

Here is an Example of what this would look like:

REACT_APP_CANDY_MACHINE_CONFIG=6ngLWVih575JqcoUuAH8yBjbCzi6HhHXDb1XqNRYAaFd

REACT_APP_CANDY_MACHINE_ID=J8of4TNnDhukY6JuhEVUHk52mUrDinFAqM5HggRTkf2q

REACT_APP_TREASURY_ADDRESS=EqYkTTEe4z342BKH6wn2FCYgyhoiNZri6RgAzUrMw2Eg

REACT_APP_CANDY_START_DATE=1634577300

REACT_APP_SOLANA_NETWORK=devnet (if you want be on mainnet replace it with mainnet-beta)

REACT_APP_SOLANA_RPC_HOST=Solana/ Mainnet 

After you edit .env, you need to save it and throw the following in the terminal:

  • $ yarn start

And your website should appear. If it doesn’t, simply connect to here – http://localhost:3000/

You should then click on the connect wallet button and select Phantom wallet.

Then, you should click on sold. A transaction should then appear in the Phantom wallet and we should accept it. In this example, I just mint all the NFTs.

And that’s it. In collectibles, you should now be able to see all your NFTs! I hope you found this tutorial useful and that you try using Metaplex’s Candy Machine for your NFTs.

Stay tuned for more useful NFT tutorials and content!

Tomas Velasquez

Want to work with Tomas Velasquez? We are hiring :)

Other articles you might like