NFTs on Solana: Minting 101

Zorayr Khalapyan
5 min readDec 10, 2021

Context: When I first heard about Solana, the premise was around a new blockchain hyper-optimized for scalable financial systems, more so than Ethereum. With the increase in gas fees, we have seen a significant rise in Solana, not only within DeFi but increasingly more within the NFT space. The launch of Metaplex has taken the first step to build the ecosystem around it and as Kunal Modi and I started to explore NFTs, our haunch was to try to launch our project on Solana to explore what’s new. The following is a bit of a rubber ducking style walk through around minting NFTs on Solana — hope you find it useful on your journey!

How Does Minting Work?

Some quick searches, give us two quick tutorials: How to Mint an NFT on Solana and How to Mint an NFT on Solana Using Candy Machine. Candy Machine is the CLI built by Metaplex to simplify the minting process, but before we use the tool, let’s actually understand how things work under the hood!

Seems like the core of the minting process in Solana is the Token Program. Unlike Ethereum where each token is a contract that abides by a specific interface (ERC20 and ERC721), in Solana we have an in-chain program responsible for minting tokens (aka the “token program”).

Interestingly, both fungible and fungible tokens in Solana are represented as regular tokens minted by the Token Program! However, to make a token non-fungible, you must create it with the flag --decimals 0 which will prevent fractionalization of the token amounts i.e. you can’t have 0.1 Crypto Kitties.

Other interesting observation is that Solana requires each token to be stored in an account of its type. If you want to have two different tokens in your wallet, you would have two different accounts!

Also as a quick side note, there are two types of accounts you can have: a program account and a storage account. Technically a simplification, but this would be an equivalent of splitting a Solidity contract into code and storage accounts. Solana Account Model goes into further details of how it’s different than EVM. But the quick take away is if your account is storing any data it’s a data account.

So what’s happening really is we are asking the token program to give us a data account that stores some metadata about our token like it’s unique identifier and number minted. When we need to mint more, we give this account which is known as the mint account to the token program and ask it to make more of it and put it into another account. Pretty simple?

Setting up Solana CLI for Minting

To further understand the setup, let’s use Solana Program Library’s CLI tool to mint a single NFT object 🙂 if you haven’t done so, install Rust’s package manager called cargo, then use it to install spl-token-cli.

$ curl https://sh.rustup.rs -sSf | sh | source $HOME/.cargo/env
$ cargo install spl-token-cli

Solana has 3 different networks: the mainnet, the testnet and the devnet. The devnet is a low-risk environment where you can airdrop SOL tokens to yourself to use it for testing. Here is the command to use devent:

$ solana config set --url https://api.devnet.solana.com
Config File: /Users/zkhalapyan/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/zkhalapyan/.config/solana/id.json
Commitment: confirmed

Now we can either create a new wallet or import our Phantom one. I was curious to see how importing works, and found this answer here. Pretty neat!

$ solana-keygen recover 'prompt://?key=0/0'

Now we can airdrop some SOL on devnet for testing! 🪂

$ solana airdrop 1Requesting airdrop of 1 SOLSignature: 57ZPH7isFtM14kyccbdDsCVudFwfsERU84FukpnsULipd3EyQoaxHWkuSWjj7EJQLj3KJMmcMJeEK7JmpExsNEHJ1 SOL

Awesome! We got our 1 SOL to play with! You can actually go to Phantom → Settings → Change Network → Devnet and see your SOL in your wallet!

Now Let’s Mint!

We use create-token command with --decimals 0 to indicate that the token is not fractional:

$ spl-token create-token --decimals 0Creating token 5UDwRyGa3C8e6GLCS55tQ18pNmJfNzxrRHSVDhSoRT3fSignature: 72a4Ymfo85K2mHdhTRsFqaasJnJoKiqBVcoWU6QtmNH9V6TQST8dGXSrZJxP3ag49QVjfRRh9h2EcmFajbsdaQf

Now that we have our “Mint Token” i.e. the account that stores are token metadata (not the token itself), we need to mint one. Remember each token needs its own unique token account, so we need to create one to store one. To make sure we creating the right type of account we need to provide the token ID that was generated above:

$ spl-token create-account 5UDwRyGa3C8e6GLCS55tQ18pNmJfNzxrRHSVDhSoRT3fCreating account EcSkHMG2CHvYX8rBV46WTTNwT9W2wTrtHJHUvKa7mXfUSignature: 4ErVkqpzdJ2zhPR5djJjsr9VCJk69mejjHceBe2W4SHG5ozuP9RiGARBmgGmx6Xyz6DoooAKCxyPDfptZY9dJJE9

Our account is empty, but we can mint a token into it! Because we want to make a non-fungible token, we need to specify a count of 1!

$ spl-token mint 5UDwRyGa3C8e6GLCS55tQ18pNmJfNzxrRHSVDhSoRT3f 1 EcSkHMG2CHvYX8rBV46WTTNwT9W2wTrtHJHUvKa7mXfUMinting 1 tokens
Token: 5UDwRyGa3C8e6GLCS55tQ18pNmJfNzxrRHSVDhSoRT3f
Recipient: EcSkHMG2CHvYX8rBV46WTTNwT9W2wTrtHJHUvKa7mXfU
Signature: 4S9Em5TysVmnMuvV4XJcCG8A9D9TvTTDjaBHSKygCR7yS3XwWCN9sTp4MAfW8cxy6YLgTfQVDQeFrFv8xbqqD7QN

Technically, you can still mint many of it making the token fungible, so we need to so something else! What Solana recommends is disabling minting in the mint account. A bit of a clever trick, but works.

$ spl-token authorize 5UDwRyGa3C8e6GLCS55tQ18pNmJfNzxrRHSVDhSoRT3f mint --disableUpdating 5UDwRyGa3C8e6GLCS55tQ18pNmJfNzxrRHSVDhSoRT3f  Current mint authority: 6zsuBDfuvtxK5FD9tf8u8LfrYBVnxDWRhj43snmC6Qx6
New mint authority: disabled
Signature: 4SvWbj5AaMCFy7LEor3VEywJr8sgqDqGFFx7Eg7u63MKsPXa3Dc9RpRuQ8XxuSQY19Z8MGS9yYLjps4T53tnwKyr

Just as a fun test, let’s test the same command above with --enable key. Nope, it’s not working and if we further investigate with $spl-token authorize --help we can see that we can only disable minting!

We can actually see it in our Phatom Wallet:

It’s interesting that it doesn’t yet show up under collections! Let’s explore that further in our next article.

Quick Summary

  • Solana has two types of accounts: data accounts and program accounts.
  • Solana Program Library (SPL) provides core program accounts including on called “Token Program” that’s used for minting both fungible and non-fungible tokens.
  • To mint an NFT, we first create a token that can’t be fractionalized, mint a single version, then disable minting.
  • Each type of token requires its own unique account inside the wallet: two different tokens = two different accounts.

--

--