Token Metadata
Theme

Features

Minting Assets

As we discussed in the Token Metadata overview, digital assets on Solana are composed of several onchain accounts and off-chain data describing the token. On this page, we'll go over the process of minting these assets.

The minting process

Whether we want to mint a Fungible, Semi-Fungible or Non-Fungible asset, the overall process is the same:

  1. Upload off-chain data. First, we must ensure our off-chain data is ready. This means we must have a JSON file stored somewhere that describes our asset. It doesn't matter how or where that JSON file is stored, as long as it's accessible via a URI.
  2. Create onchain accounts. Then, we must create the onchain accounts that will hold our asset's data. Which exact accounts will be created depends on the Token Standard of our asset, but in all cases, a Metadata account will be created and will store the URI of our off-chain data.
  3. Mint tokens. Finally, we must mint the tokens associated with all these accounts. For Non-Fungible assets, that simply means minting from 0 to 1, since Non-Fungibility forbids us to have a supply greater than 1. For Fungible or Semi-Fungible assets, we may mint however many tokens we want.

Let's dig into these steps in more detail, whilst providing concrete code examples.

Uploading off-chain data

You may use any service to upload your off-chain data or simply store it on your own server but it is worth noting that some of our SDKs can help with that. They use a plugin system that allows you to select the uploader of your choice and offer a unified interface for you to upload your data.

Upload assets and JSON data

const [imageUri] = await umi.uploader.upload([imageFile])
const uri = await umi.uploader.uploadJson({
  name: 'My NFT',
  description: 'This is my NFT',
  image: imageUri,
  // ...
})

Now that we have our URI, we can move on to the next step.

The next steps show how to create accounts and mint the tokens in two steps. At the bottom of the page there are code examples for helpers that combine those steps and make creating different token types easier.

Creating Mint and Metadata accounts

To create all the onchain accounts required by the Token Standard of your choice, you may simply use the Create V1 instruction. It will adapt to the requested Token Standard and create the right accounts accordingly.

For instance, NonFungible assets will have a Metadata account and a MasterEdition account created, whereas Fungible assets will only have a Metadata account created.

Additionally, if the provided Mint account does not exist, it will be created for us. That way, we don't even need to call the underlying Token program to prepare our token before adding metadata to it.

This instruction accepts a variety of parameters and our SDKs do their best to provide default values to them so you don't need to fill all of them every single time. That being said, here is a list of parameters that you may be interested in:

  • Mint: The Mint account of the asset. If it doesn't exist, it must be provided as a Signer as it will be initialized. Typically, we generate a new keypair for this purpose.
  • Authority: The authority of the Mint account. This is the account that is or will be allowed to mint tokens from the Mint account. This will default to the "Identity" wallet — i.e. the connected wallet — if supported by the SDK.
  • Name, URI, Seller Fee Basis Points, Creators, etc.: The data of the asset to store on the Metadata account.
  • Token Standard: The Token Standard of the asset.

createV1 is a helper function that can initialize the Mint Account and create the Metadata Account. If the mint exists already it will only create the metadata Account. If you are looking on how to use createMetadataAccountV3 you should be using this function instead.

Create onchain Accounts

import { generateSigner, percentAmount } from '@metaplex-foundation/umi'
import {
  createV1,
  TokenStandard,
} from '@metaplex-foundation/mpl-token-metadata'

const mint = generateSigner(umi)
await createV1(umi, {
  mint,
  authority,
  name: 'My NFT',
  uri,
  sellerFeeBasisPoints: percentAmount(5.5),
  tokenStandard: TokenStandard.NonFungible,
}).sendAndConfirm(umi)

Minting Tokens

Once all onchain accounts are created for our asset, we can mint tokens for it. If the asset is Non-Fungible we will simply mint its one and only token, otherwise we can mint as many tokens as we want. Note that a Non-Fungible asset is only valid once its unique token has been minted so it is a mandatory step for that Token Standard.

We can use the Mint V1 instruction of the Token Metadata program to achieve this. It requires the following parameters:

  • Mint: The address of the asset's Mint account.
  • Authority: The authority that can authorize this instruction. For Non-Fungible assets, this is the update authority of the Metadata account, otherwise, this refers to the Mint Authority of the Mint account.
  • Token Owner: The address of the wallet to receive the token(s).
  • Amount: The number of tokens to mint. For Non-Fungible assets, this may only be 1.
  • Token Standard: The Token Standard of the asset (required for our JavaScript SDK). The program does not require this argument but our SDK do so they can provide adequate default values for most of the other parameters.

Mint Tokens

import { mintV1, TokenStandard } from '@metaplex-foundation/mpl-token-metadata'

await mintV1(umi, {
  mint: mint.publicKey,
  authority,
  amount: 1,
  tokenOwner,
  tokenStandard: TokenStandard.NonFungible,
}).sendAndConfirm(umi)

Create Helpers

Since creating digital assets is such an important part of Token Metadata, our SDKs provide helper methods to make the process easier. Namely, these helper methods combine the Create V1 and Mint V1 instructions together in different ways, depending on the Token Standard we want to create.

Create helpers

Previous
Token Standards (Assets)