import{Connection,Keypair}from"@solana/web3.js";importbs58from"bs58";import'dotenv/config'// Replace with your GetBlock endpointconstGETBLOCK_RPC_URL=process.env.RPC_URL;// Create connection to Solana via GetBlockconstconnection=newConnection(GETBLOCK_RPC_URL,"confirmed");// Load keypair from private key in .env constpayer=Keypair.fromSecretKey(bs58.decode(process.env.PRIVATE_KEY));export{connection,payer};
Create a Token with Metadata Extension
1
Create a new file index.js . This will serve as your working file
2
Import all the dependencies:
3
Generate an account for the mint address
4
Define the token metadata:
5
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.
6
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.
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.
This guide uses Solana Devnet. If you want to make use of Mainnet, go to your account dashboard and get a Solana mainnet access token.