快速入门
铸造同质化代币
Last updated November 28, 2025
铸造更多同质化代币以增加Solana上代币的流通供应量。
铸造代币
在以下部分,您可以看到完整的代码示例以及需要更改的参数。这假设您已经创建了同质化代币,现在想要铸造更多代币。
1// To install all the required packages use the following command
2// npm install @metaplex-foundation/mpl-toolbox @metaplex-foundation/umi @metaplex-foundation/umi-bundle-defaults
3import {
4 createTokenIfMissing,
5 findAssociatedTokenPda,
6 mintTokensTo,
7} from '@metaplex-foundation/mpl-toolbox';
8import {
9 keypairIdentity,
10 publicKey,
11 transactionBuilder,
12} from '@metaplex-foundation/umi';
13import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
14import { readFileSync } from 'fs';
15
16// Initialize Umi with Devnet endpoint
17const umi = createUmi('https://api.devnet.solana.com')
18
19// Load your wallet/keypair
20const wallet = '<your wallet file path>'
21const secretKey = JSON.parse(readFileSync(wallet, 'utf-8'))
22const keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secretKey))
23umi.use(keypairIdentity(keypair))
24
25// Your token mint address and destination wallet
26const mintAddress = publicKey('<your token mint address>')
27const destinationAddress = publicKey('<destination wallet address>')
28
29// Find the destination token account
30const destinationTokenAccount = findAssociatedTokenPda(umi, {
31 mint: mintAddress,
32 owner: destinationAddress,
33})
34
35// Create the destination token account if it doesn't exist and mint tokens
36await transactionBuilder()
37 .add(createTokenIfMissing(umi, {
38 mint: mintAddress,
39 owner: destinationAddress,
40 }))
41 // Mint 100 tokens to the destination
42 .add(
43 mintTokensTo(umi, {
44 mint: mintAddress,
45 token: destinationTokenAccount,
46 amount: 100,
47 }))
48 .sendAndConfirm(umi)
49
50console.log('Minted 100 tokens')
51console.log('Mint:', mintAddress)
52console.log('To:', destinationTokenAccount)
1# Mint Additional Tokens using the Metaplex CLI
2
3# Mint tokens to your own wallet (default)
4# Usage: mplx toolbox token mint <MINT_ADDRESS> <AMOUNT>
5mplx toolbox token mint <MINT_ADDRESS> <AMOUNT>
6
7# Mint tokens to a specific recipient
8mplx toolbox token mint <MINT_ADDRESS> <AMOUNT> --recipient <RECIPIENT_ADDRESS>
9
10# Example: Mint 1000 tokens (0 decimals) to your wallet
11mplx toolbox token mint 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU 1000
12
13# Example: Mint 1000 tokens (9 decimals) to your wallet
14# Amount is in smallest units: 1000 * 10^9 = 1000000000000
15mplx toolbox token mint 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU 1000000000000
16
17# Example: Mint tokens to another wallet
18mplx toolbox token mint 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU 1000 \
19 --recipient 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
20
21# Note: You must be the mint authority to mint additional tokens
参数
根据您的铸造操作自定义以下参数:
| 参数 | 描述 |
|---|---|
mintAddress | 代币铸币地址 |
destinationAddress | 接收代币的钱包地址 |
amount | 要铸造的代币数量 |
工作原理
铸造过程涉及3个步骤。根据您使用的工具,您可能需要手动执行这些步骤,也可能不需要。以下步骤侧重于umi:
- 查找目标代币账户 - 使用
findAssociatedTokenPda定位接收者的代币账户 - 如有需要创建代币账户 - 使用
createTokenIfMissing确保接收者有代币账户 - 铸造代币 - 使用
mintTokensTo执行铸造
要求
要铸造更多代币,您必须是铸币权限者 - 只有指定为铸币权限者的钱包才能铸造新代币
重要说明
- 根据您使用的工具,您可能需要考虑小数位数。
amount需要考虑小数位数(例如,如果是9位小数,铸造1个代币需要amount: 1_000_000_000) - 您可以铸造到任何钱包地址——如果代币账户不存在,它将被创建
- 只有铸币权限者可以铸造新代币
