Guide Overiew
After what felt like walking through a mine field trying to figure out how to create my own NFT on Solana with the current guides, I decided to put together a guide myself in a very beginner friendly fashion.
I won't be taking a deeper dive into the specifics of how everything works, but rather help people with zero knowledge of rust obtain a general understanding on how to create their very own NFT on Solana with the help of Metaplex candy machine and a web starter kit.
Note: I used Ubuntu 21.10 - Wayland for it. Some things may vary depending on the operating system you are running.
What is a Metaplex Candy Machine?
Metaplex
is a command line tool that interacts with the candy-machine program. In this guide, we will use it to:
- Upload your images along with their metadata to arweave, then register them on the Solana blockchain.
- Verify that the state of your candy machine is valid and complete.
- Mint individual tokens.
Candy Machine
is a system that manages fair mints.
• The minting process starts and finishes at the same time for everyone.
• It won't accept your funds if there are no more NFTs to sell.
Prerequisites
- NodeJS (version 14.17.6)
- SolanaCLI
- Metaplex CLI
- Phantom Wallet
If you have a different version of Node installed on your system, you can use nvm which allows you to quickly install and use different versions of node via the command line.
Getting Started
Installing The SolanaCLI
Solana already has really well made guides on installing and using the Solana command line.
• Install Solana Command Line Tools
Using Devnet
Devnet is really useful for developers to test out their programs and applications.
You can set your default Solana url to devnet using:
$ solana config set --url https://api.devnet.solana.com
Now, let's create a devnet wallet:
$ solana-keygen new --outfile ~/.config/solana/devnet.json
Remember to store your seed phrase somewhere safe.
I highly recommend making devnet your default keypair
$ solana config set --keypair ~/.config/solana/devnet.json
Funding The Devnet Wallet
Firstly, let’s make sure that we’re on devnet by checking the configuration.
$ solana config get
//Output:
Config File: /Users/dev/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/dev/.config/solana/devnet.json
Commitment: confirmed
Now, let’s fund that wallet:
Firstly, We check the balance of our current wallet.
$ solana balance
//Output:
0 SOL
Then we airdrop the amount of SOL to our wallet. Remember, the amount is capped to 5 SOL.
$ solana airdrop 4
//Output
Requesting airdrop of 4
Signature: Transaction Signature
4 SOL
Now, Let’s check our balance to confirm the airdrop was successful.
$ solana balance
//Output:
4 SOL //This can vary depending on the balance you initially had.
In case you’re confused by any of the above steps, you can check the manuals to get a better understanding by running:
$ solana help config
$ solana help balance
$ solana help airdrop
Configuring Phantom Wallet
After setting up your phantom wallet, we can link our newly created devnet wallet above to phantom.
To do so, first we need to open its settings, click on Change Network
and select Devnet
Now, we need to obtain the devnet wallet private key. To obtain that, open your terminal and cat
to view the contents of the keypair.json
file
$ cat .config/solana/devnet.json
//Output:
[12,22,.....]
Now copy the output you received and open phantom wallet. Click on the top left navigation menu and click on Add/Connect Wallet
and then click on Import Private Key
and give it a suitable name and paste the contents we copied before in the Private Key field.
You should be able to see 4 SOL in your wallet.
Running Candy Machine CLI
Please ensure that you have node
and yarn
installed before proceeding.
Also install ts-node
by running:
$ npm install -g ts-node
Now, let’s clone the metaplex project into the location of your choice.
$ git clone https://github.com/metaplex-foundation/metaplex.git
$ cd metaplex/js
$ yarn install && yarn bootstrap && yarn build
To run the command line utility,
$ ts-node metaplex/js/packages/cli/src/candy-machine-cli.ts help
Usage: candy-machine-cli [options] [command]
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
upload [options] <directory>
verify [options]
verify_price [options]
create_candy_machine [options]
update_candy_machine [options]
mint_one_token [options]
sign [options]
sign_candy_machine_metadata [options]
help [command] display help for command
Organizing & Uploading Your Assets
For this guide, we will be using pre-made assets which you can download by clicking here. courtesy of solana-candy-factory
Place this assets
folder in a suitable location.
Here is how you should organize your NFT files to upload:
ls assets | sort -n
0.json
0.png
1.json
1.png
2.json
2.png
3.json
3.png
....
You can notice that these files come in numerical pairs, that is 1.png
and 1.json
are the two halves of the NFT. The png
file is the art work and the json
file contains the metadata.
The directory name assets
does not matter. You can go with anything you like.
Validating Your Assets
This may feel tedious but it's just as important. Checkout the the manual on carrying this out at
https://docs.metaplex.com/nft-standard
Uploading Your Project Assets
Now that we have the funds, assets all organized and vaidated, we can proceed with the fun stuff!
We will proceed with uploading our assets with the CLI. Remember, our assets are located at metaplex\js\packages\cli\example-assets
$ ts-node metaplex/js/packages/cli/src/candy-machine-cli.ts upload assets --env devnet --keypair ~/.config/solana/devnet.json
//Output
Processing file: 0
Processing file: 1
Processing file: 2
Processing file: 3
Done
By uploading, it sends the files to Arweave and also registers those files with your candy machine. Both Arweave and Solana are initialized after a successful run.
Validating Your Candy Machine
You can confirm the health and status of your on-chain assets using:
$ ts-node metaplex/js/packages/cli/src/candy-machine-cli.ts verify --env devnet --keypair ~/.config/solana/devnet.json
//Output:
Looking at key 0
Name {redacted-name} 0 with https://arweave.net/{redacted-tx-id} checked out
Looking at key 1
Name {redacted-name} 1 with https://arweave.net/{redacted-tx-id} checked out
Looking at key 2
Name {redacted-name} 2 with https://arweave.net/{redacted-tx-id} checked out
Looking at key 3
Name {redacted-name} 3 with https://arweave.net/{redacted-tx-id} checked out
Starting Your Candy Machine
After verifying that our assets are good to go, we can finally start the candy machine.
$ ts-node metaplex/js/packages/cli/src/candy-machine-cli.ts create_candy_machine --env devnet --keypair ~/.config/solana/devnet.json
Updating Your Candy Machine
We can modify our candy machine details to include a start date and/or price etc.
$ ts-node metaplex/js/packages/cli/src/candy-machine-cli.ts update_candy_machine --env devnet --keypair ~/.config/solana/devnet.json --price 1 --date "29 Oct 2021 00:12:00 GMT"
Minting Our NFT
To mint our NFT, we can use mint_one_token
like so:
$ ts-node metaplex/js/packages/cli/src/candy-machine-cli.ts mint_one_token --env devnet --keypair ~/.config/solana/devnet.json
If all goes well, you can now open your phantom wallet, open the collectibles page (It's beside the $ symbol on the bottom) and voila! Your newly minted NFT will be there!
Setting Up The Web Starter Kit
Now that we've successfully minted an NFT into our wallet, let's make a web application to carry out the mint instead!
Note: This project is very new and could cause some issues, if it does then please report it on github.
The goal of the project is for you to be able to configure it and customize it to your liking.
Fork the project and then clone it to your desired location.
Link: https://github.com/exiled-apes/candy-machine-mint
Now we need to build the project,
cd candy-machine-mint
yarn install
yarn build
This is where things get a little bit complicated. When we uploaded our NFTs, a cache file was created in the same directory as our assets directory. However, this .cache
folder is hidden! If you're on ubuntu, use ctrl+h
to display hidden files.
Once you have discovered that folder, open it and you'll find devnet-temp
file. Open it in your IDE and you'll see the following
{
"program": {
"uuid": "Ch3xxx",
"config": "Ch3xxx"
},
"items": {
"0": {
"link": "https://arweave.net/xxxx",
"name": "TEST",
"onChain": true
},
"1": {
"link": "https://arweave.net/xxxx",
"name": "TEST",
"onChain": true
},
"2": {
"link": "https://arweave.net/xxxx",
"name": "TEST",
"onChain": true
},
"3": {
"link": "https://arweave.net/xxxx",
"name": "TEST",
"onChain": true
},
"4": {
"link": "https://arweave.net/xxxx",
"name": "TEST",
"onChain": true
},
"5": {
"link": "https://arweave.net/xxxx",
"name": "TEST",
"onChain": true
}
},
"env": "devnet",
"cacheName": "temp",
"authority": "9xJxxxx",
"candyMachineAddress": "3Wmxxxx",
"startDate": 1632615120
}
We're going to need all this data when we run our web application to mint.
Configuring Candy-Machine-Mint
Open up the candy-machine-mint folder, where you will find a file called .env.example
(The file is usually hidden, use ctrl+h
to display hidden files)
Rename it to .env
and then open it to edit the following details:
REACT_APP_CANDY_MACHINE_CONFIG=__PLACEHOLDER__
This is the program.config
key from our .cache/devnet-temp
file.
REACT_APP_CANDY_MACHINE_ID=__PLACEHOLDER__
This is the candyMachineAddress
from our .cache/devnet-temp
file.
REACT_APP_TREASURY_ADDRESS=__PLACEHOLDER__
This the Solana address that receives the funds gathered during the minting process. This is the authority
from our .cache/devnet-temp
file.
REACT_APP_CANDY_START_DATE=__PLACEHOLDER__
This is the startDate
key from our .cache/devnet-temp
file.
Note: If you cannot find it, use update_candy_machine
as mentioned above as you may have missed out on mentioning the date.
REACT_APP_SOLANA_NETWORK=devnet
This identifies the Solana network you want to connect to. Options are devnet, testnet, and mainnet.
REACT_APP_SOLANA_RPC_HOST=https://explorer-api.devnet.solana.com
This identifies the RPC server your web app will access the Solana network through.
Starting The Web Application
Open your terminal and navigate to the candy-machine-mint
directory and start the react app by using yarn start
Once you see Compiled Successfully in your terminal, Open http://localhost:3000 to view it in the browser.
You can now proceed with connecting your wallet, and clicking on the mint button.
After clicking on the mint button, you can check the collectibles page on your phantom wallet and you'll see your newly minted NFT!
That’s all I will be covering in this guide. If you encounter any issues, comment down below and I’ll try to help!
Other Resources
- https://hackmd.io/@levicook/HJcDneEWF
- https://docs.metaplex.com/
- Solana Discord
- Follow Anatoly and Raj Gokal for good vibes.
Ps. If you made it till here, leave a like and a comment with your feedback! Oh and a follow would be over the top appreciated :')
Top comments (17)
thanks, I followed your tutorial, but I got one error trying mint a NFT from web page, which says "Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'digest')", I check candy-machine/.env file many times.
Hey ccamaleon5! Could you reach out to me on Discord? I'd love to help you out solve this. My Discord Tag: Devind Dev#2806
I believe this may be caused by the treasury address value, set it as value of authority you find in your devnet-temp file and try.
Update: I was able to reproduce the error by opening the web app via 192.168.x.x:3000
More on this: stackoverflow.com/questions/571465...
You can try running it as localhost:3000 and it should work properly.
i really really need some help. i have added you, accept the frnd request. my name is Samartha#3954, wanna have a advisory chat with you :)
Requires correction in $ ts-node metaplex/js/packages/cli/src/candy-machine-cli.ts upload assets --env devnet --keypair ~/.config/solana/devnet.json
It should be candy-machine-v2-cli.ts for "upload" option.
Rest superb blog.
Thanks for this guide, Devind. We published an updated guide for Candy Machine V2 (more recent) - you can find the guide here: Easy Guide To Mint Solana NFTs Using Candy Machine V2. There are several feature upgrades in V2. Feel free to update the article here with the info from our V2 guide.
Thanks ! Awesome!
Thanks for this publication, if I create a collection of 2000 NFT, but in this first stage, I want to create a candy of 500, and in a few months to create another of 500, would this be a problem? are they associated in the same collection?
Thanks.
Yeah sure! That's not a problem but remember to create a new candy machine for it as you can't add more items to an existing candy machine
Hi. I would like to discuss this further with you and develop a long-term collaboration. Would that be possible? Thanks.
Write me on cosmin.pert@gmail.com or whatsapp / telegram +40 762 300 010
\metaplex> solana airdrop 1
Requesting airdrop of 1 SOL
Error: unable to confirm transaction. This can happen in situations such as transaction expiration and insufficient fee-payer funds
Check your keypair and api
hi, I am not able to see the SOL in phantom wallet. Please resolve my problem.
Hey! Did you change it to devnet?
once nft has been uploaded on metaplex, are we still able to make any changes etc?
Hello! How can I contact you ?