功能

铸造压缩NFT

Last updated February 24, 2026

Summary

Minting compressed NFTs adds new cNFTs to a Bubblegum Tree using the mintV2 instruction. This page covers minting with and without MPL-Core collections, and retrieving the asset ID from mint transactions.

  • Mint cNFTs to a Bubblegum Tree using the mintV2 instruction
  • Mint directly into an MPL-Core collection with the BubblegumV2 plugin
  • Retrieve the asset ID and leaf schema from the mint transaction
  • Configure metadata including name, URI, creators, and royalties

上一页中,我们看到需要一个Bubblegum树来铸造压缩NFT,以及如何创建一个。现在,让我们看看如何从给定的Bubblegum树铸造压缩NFT。

Bubblegum程序为不同的叶子模式版本提供多个铸造指令。Bubblegum V2引入了一个新的铸造指令,名为mintV2,用于将压缩NFT铸造到给定的集合或不带集合。

不带集合铸造

Bubblegum程序提供mintV2指令,使我们能够从Bubblegum树铸造压缩NFT。如果Bubblegum树是公开的,任何人都可以使用此指令。否则,只有树创建者或树委托人才能这样做。

mintV2指令的主要参数是:

  • 默克尔树:将从中铸造压缩NFT的默克尔树地址。
  • 树创建者或委托人:允许从Bubblegum树铸造的权限——这可以是树的创建者或委托人。此权限必须签署交易。对于公开树,此参数可以是任何权限,但仍然必须是签名者。
  • 叶子所有者:将被铸造的压缩NFT的所有者。默认为交易的付款人。
  • 叶子委托人:允许管理铸造的cNFT的委托权限(如果有)。否则,设置为叶子所有者。
  • 集合权限:允许管理给定集合的权限。
  • Core集合:压缩NFT将添加到的MPL-Core集合NFT。
  • 元数据:将被铸造的压缩NFT的元数据。它包含诸如NFT的名称、其URI、其集合、其创作者等信息。在Bubblegum V2中,元数据使用MetadataArgsV2,它排除了不需要的字段,如uses和集合的verified标志。

不带集合铸造压缩NFT

import { none } from '@metaplex-foundation/umi';
import { mintV2 } from '@metaplex-foundation/mpl-bubblegum';
await mintV2(umi, {
leafOwner: umi.identity.publicKey,
merkleTree: merkleTree.publicKey,
metadata: {
name: 'My NFT',
uri: 'https://example.com/my-nft.json',
sellerFeeBasisPoints: 550,
collection: none(),
creators: [],
},
}).sendAndConfirm(umi);

铸造到集合

虽然可以在铸造压缩NFT_之后_为其设置和验证集合,但Bubblegum V2允许您直接将压缩NFT铸造到给定的集合。Bubblegum V2使用MPL-Core集合对压缩NFT进行分组。为此使用相同的mintV2指令。除了上述参数外,您还需要传入核心集合并作为集合权限或委托人签名:

  • Core集合:传递给coreCollection参数的铸造地址,指向MPL-Core集合NFT…
  • 集合权限:允许管理给定集合NFT的权限。这可以是集合NFT的更新权限或委托的集合权限。无论Bubblegum树是否公开,此权限必须签署交易。

请注意,元数据参数必须包含集合公钥。

将压缩NFT铸造到集合

import { some } from '@metaplex-foundation/umi';
import { mintV2 } from '@metaplex-foundation/mpl-bubblegum';
await mintV2(umi, {
collectionAuthority: umi.identity,
leafOwner: umi.identity.publicKey,
merkleTree: merkleTree.publicKey,
coreCollection: collectionSigner.publicKey,
metadata: {
name: 'My NFT',
uri: 'https://example.com/my-nft.json',
sellerFeeBasisPoints: 550, // 5.5%
collection: some(collectionSigner.publicKey),
creators: [],
},
}).sendAndConfirm(umi);

从铸造交易获取资产ID和叶子模式

您可以使用parseLeafFromMintV2Transaction辅助函数从mintV2交易中检索叶子并确定资产ID。此函数解析交易,因此您必须确保在调用parseLeafFromMintV2Transaction之前交易已完成。

交易完成

请确保在调用parseLeafFromMintV2Transaction之前交易已完成。

从铸造交易获取叶子模式

import {
mintV2,
parseLeafFromMintV2Transaction,
} from '@metaplex-foundation/mpl-bubblegum';
const { signature } = await mintV2(umi, {
// ... 详见上文
}).sendAndConfirm(umi);
const leaf = await parseLeafFromMintV2Transaction(umi, signature);
const assetId = leaf.id;

Notes

  • The Bubblegum Tree must be created before minting. See Creating Trees.
  • For collection mints, the MPL-Core collection must have the BubblegumV2 plugin enabled.
  • The collection authority must sign the transaction when minting to a collection, regardless of whether the tree is public or private.
  • Use parseLeafFromMintV2Transaction only after the transaction is finalized, not just confirmed.

FAQ

Glossary

TermDefinition
mintV2The Bubblegum V2 instruction for minting compressed NFTs, replacing the V1 mint instructions
MetadataArgsV2The metadata structure passed to mintV2, containing name, URI, royalties, collection, and creators
Collection AuthorityThe signer authorized to manage the MPL-Core collection — required when minting to a collection
BubblegumV2 PluginAn MPL-Core collection plugin that enables Bubblegum V2 features (freeze, soulbound, royalties)
Asset IDA PDA derived from the merkle tree address and leaf index, uniquely identifying a compressed NFT
Leaf SchemaThe data structure stored as a leaf in the merkle tree, containing the cNFT's hashed metadata and ownership info