How to Create Tokens With Metadata On Solana Using Token-2022
Create Solana SPL tokens with metadata using Token-2022 program — developer guide
Now that you have learnt about token extension, in this guide, you will be learning how to create a simple token with metadata extension
Prerequistics
Before you begin, ensure you have the following:
Node installed on your PC, preferably v20+
A package manager such as npm or yarn
Solana Access token from GetBlock
Basic knowledge of JavaScript and Typescript
Basic understanding of Solana (wallets, transactions, lamports)
Set up your environment
Create a new project directory:
Install required dependencies:
Create a .env file and add the following:
Configuration File
Create config.js file and add the following:
Create a Token with Metadata Extension
Create a new file index.js . This will serve as your working file
Import all the dependencies:
Generate an account for the mint address
Define the token metadata:
Calculate the metadata space and rent needed for the mint account:
This ensures our token mint account has sufficient space for the extensions you use or else the metadata initialization would fail with an insufficient lamports error.
Define the structure of the transaction:
This creates the mint address, initializes the mint, metadata, points to the mint itself as the metadata account, and sends the transaction.
Run the code using this command:
Conclusion
In this guide, you have learnt how to create a token with metadata extension. This guide also walks you through generating a Mint account for your token.
Additional Resources
Last updated
Was this helpful?
