快速入门

铸造同质化代币

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)

参数

根据您的铸造操作自定义以下参数:

参数描述
mintAddress代币铸币地址
destinationAddress接收代币的钱包地址
amount要铸造的代币数量

工作原理

铸造过程涉及3个步骤。根据您使用的工具,您可能需要手动执行这些步骤,也可能不需要。以下步骤侧重于umi:

  1. 查找目标代币账户 - 使用findAssociatedTokenPda定位接收者的代币账户
  2. 如有需要创建代币账户 - 使用createTokenIfMissing确保接收者有代币账户
  3. 铸造代币 - 使用mintTokensTo执行铸造

要求

要铸造更多代币,您必须是铸币权限者 - 只有指定为铸币权限者的钱包才能铸造新代币

重要说明

  • 根据您使用的工具,您可能需要考虑小数位数。amount需要考虑小数位数(例如,如果是9位小数,铸造1个代币需要amount: 1_000_000_000
  • 您可以铸造到任何钱包地址——如果代币账户不存在,它将被创建
  • 只有铸币权限者可以铸造新代币