Getting Started
Create a Fungible Token
Create a fungible token with metadata on Solana using the Token Metadata program.
What You'll Learn
This guide shows you how to create and mint a fungible token with:
- Custom name, symbol, and metadata
- Token image and description
- Configurable decimals (divisibility)
- Initial token supply
Create a Token
The following code is a fully runnable example. Below the parameters that you might want to customize are shown. You can learn more about token creation details in the Token Metadata program pages.
// To install all the required packages use the following command
// npm install @metaplex-foundation/mpl-token-metadata @metaplex-foundation/umi @metaplex-foundation/umi-bundle-defaults
import {
createAndMint,
mplTokenMetadata,
TokenStandard,
} from '@metaplex-foundation/mpl-token-metadata';
import {
generateSigner,
keypairIdentity,
percentAmount,
some,
} from '@metaplex-foundation/umi';
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { readFileSync } from 'fs';
// Initialize Umi with Devnet endpoint
const umi = createUmi('https://api.devnet.solana.com').use(mplTokenMetadata())
// Load your wallet/keypair
const wallet = '<your wallet file path>'
const secretKey = JSON.parse(readFileSync(wallet, 'utf-8'))
const keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secretKey))
umi.use(keypairIdentity(keypair))
// Generate a new mint account
const mint = generateSigner(umi)
// Create and mint the fungible token with metadata
// The minted tokens will be sent to the umi identity address
createAndMint(umi, {
mint,
name: 'My Fungible Token',
symbol: 'MFT',
uri: 'https://arweave.net/7BzVsHRrEH0ldNOCCM4_E00BiAYuJP_EQiqvcEYz3YY',
sellerFeeBasisPoints: percentAmount(5.5),
decimals: some(9),
tokenStandard: TokenStandard.Fungible,
amount: 1000,
}).sendAndConfirm(umi)
console.log('Fungible token created:', mint.publicKey)
Parameters
Customize these parameters for your token:
| Parameter | Description |
|---|---|
name | Token name (max 32 characters) |
symbol | Short name of your Token (max 6 characters) |
uri | Link to off-chain metadata JSON |
sellerFeeBasisPoints | Royalty percentage (550 = 5.5%) |
decimals | Decimal places (some(9) is standard) |
amount | Number of tokens to mint |
Metadata and Images
The uri should point to a JSON file containing at least the following information. You can find more details on the Token Metadata Standard page. You need to upload the JSON and the image url so that they are accessible from everywhere. We recommend to use a web3 storage provider like Arweave. If you want to do so by code you can follow this guide.
{
"name": "My Fungible Token",
"symbol": "MFT",
"description": "A fungible token on Solana",
"image": "https://arweave.net/tx-hash"
}