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.
1// npm install @metaplex-foundation/mpl-token-metadata @metaplex-foundation/mpl-toolbox @metaplex-foundation/umi @metaplex-foundation/umi-bundle-defaults
2import {
3 createFungible,
4 mplTokenMetadata,
5} from '@metaplex-foundation/mpl-token-metadata'
6import {
7 createTokenIfMissing,
8 findAssociatedTokenPda,
9 mintTokensTo,
10} from '@metaplex-foundation/mpl-toolbox'
11import {
12 generateSigner,
13 keypairIdentity,
14 percentAmount,
15 some,
16} from '@metaplex-foundation/umi'
17import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
18import { readFileSync } from 'fs'
19
20// Initialize Umi with your RPC endpoint
21const umi = createUmi('https://api.devnet.solana.com').use(mplTokenMetadata())
22
23// Load your wallet keypair
24const wallet = '<your wallet file path>'
25const secretKey = JSON.parse(readFileSync(wallet, 'utf-8'))
26const keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secretKey))
27umi.use(keypairIdentity(keypair))
28
29// Generate a new mint account
30const mint = generateSigner(umi)
31
32// Step 1: Create the fungible token with metadata
33await createFungible(umi, {
34 mint,
35 name: 'My Fungible Token',
36 symbol: 'MFT',
37 uri: 'https://example.com/my-token-metadata.json',
38 sellerFeeBasisPoints: percentAmount(0),
39 decimals: some(9),
40}).sendAndConfirm(umi)
41
42// Step 2: Mint initial supply to your wallet
43await createTokenIfMissing(umi, {
44 mint: mint.publicKey,
45 owner: umi.identity.publicKey,
46})
47 .add(
48 mintTokensTo(umi, {
49 mint: mint.publicKey,
50 token: findAssociatedTokenPda(umi, {
51 mint: mint.publicKey,
52 owner: umi.identity.publicKey,
53 }),
54 amount: 1_000_000_000_000_000, // 1,000,000 tokens with 9 decimals
55 })
56 )
57 .sendAndConfirm(umi)
58
59console.log('Token created:', mint.publicKey)
60console.log('Metadata and mint account initialized')
61console.log('Initial supply minted to:', umi.identity.publicKey)
1
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"
}
