功能

铸造压缩NFT

Last updated October 1, 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
  • 从 MPL-Core 集合的 Royalties 插件继承 seller fee basis points

在上一页中,我们看到需要一个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);

从集合继承版税

铸造到 MPL-Core 集合时,可以在叶子上存储哨兵 seller fee basis points 值(65535,导出为 SELLER_FEE_BASIS_POINTS_INHERIT / 0xffff),而不是将集合的版税百分比复制到每个 cNFT。DAS 将集合解析后的费率放在 royalty.basis_points / creators 上供展示,并将叶子哨兵放在 royalty.basis_points_raw / creators_raw 上(同时 royalty.inherited: true),而链上叶子为哈希保留哨兵值。

读取 DAS 响应的客户端(钱包、市场、索引器与应用)应遵循读取继承版税。

市场 / 索引器兼容性

在钱包或市场的 DAS 提供商支持继承 SFBP 解析之前,它会看到 creators: [] 与 basis_points: 65535。应用随后会显示 655.35% 的版税(约 650%)且没有 creators,并可能跳过版税支付。链上资产是正确的。详见不支持继承版税的 DAS 提供方的响应。为更强保证,请使用集合 Royalties 插件的允许/拒绝列表,使销售经过版税合规场所。

当提供了 coreCollection 且省略 metadata.sellerFeeBasisPoints 时,JavaScript SDK 的 mintV2 辅助函数默认使用此行为。

要求:

  • MPL-Core 集合必须同时具有 BubblegumV2 和 Royalties 插件。
  • 使用继承 seller fee 时,metadata.creators 必须是空数组。创作者分配来自集合的 Royalties 插件,而非叶子级创作者。
  • 继承 seller fee 仅对集合中的 cNFT 有效。无集合铸造必须使用 0 到 10000 之间的明确值。
1import { createTreeV2, mintV2, mplBubblegum } from '@metaplex-foundation/mpl-bubblegum'
2import { createCollection, mplCore, ruleSet } from '@metaplex-foundation/mpl-core'
3import { generateSigner, some } from '@metaplex-foundation/umi'
4import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
5
6const umi = createUmi('https://api.devnet.solana.com')
7 .use(mplBubblegum())
8 .use(mplCore())
9
10const merkleTree = generateSigner(umi)
11const collectionSigner = generateSigner(umi)
12
13await createTreeV2(umi, {
14 merkleTree,
15 maxDepth: 5,
16 maxBufferSize: 8,
17}).sendAndConfirm(umi)
18
19// The collection must include BubblegumV2 and Royalties plugins.
20await createCollection(umi, {
21 collection: collectionSigner,
22 name: 'My Collection',
23 uri: 'https://example.com/collection.json',
24 plugins: [
25 { type: 'BubblegumV2' },
26 {
27 type: 'Royalties',
28 basisPoints: 500, // 5%
29 creators: [{ address: umi.identity.publicKey, percentage: 100 }],
30 ruleSet: ruleSet('None'),
31 },
32 ],
33}).sendAndConfirm(umi)
34
35// sellerFeeBasisPoints is omitted — the SDK sends the inherit sentinel (65535).
36await mintV2(umi, {
37 collectionAuthority: umi.identity,
38 leafOwner: umi.identity.publicKey,
39 merkleTree: merkleTree.publicKey,
40 coreCollection: collectionSigner.publicKey,
41 metadata: {
42 name: 'My NFT',
43 uri: 'https://example.com/my-nft.json',
44 collection: some(collectionSigner.publicKey),
45 creators: [], // must be empty when inheriting royalties
46 },
47}).sendAndConfirm(umi)
48
49// cNFT minted with SELLER_FEE_BASIS_POINTS_INHERIT (65535) on the leaf

你仍可以传入明确的 sellerFeeBasisPoints 以覆盖单次铸造的集合默认值。

移除集合

具有继承 seller fee 的 cNFT 在 seller fee 更新为明确值之前无法从集合中移除。请参阅管理集合和更新压缩 NFT。

从铸造交易获取资产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.
  • 要从集合继承版税,集合还必须具有 Royalties 插件,且叶子的 creators 数组必须为空。
  • 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

如何将压缩 NFT 铸造到集合中?

使用 mintV2 指令,将 coreCollection 参数设置为 MPL-Core 集合地址,并提供 collectionAuthority 签名者。集合必须启用 BubblegumV2 插件。

铸造后如何获取资产 ID?

在交易完成后使用 parseLeafFromMintV2Transaction 辅助函数。它会解析交易并通过 leaf.id 返回包含资产 ID 的叶子模式。

任何人都可以从我的树铸造吗?

仅当树以 public: true 创建时才可以。对于私有树,只有树创建者或树委托人可以铸造 cNFT。

铸造需要哪些元数据字段?

MetadataArgsV2 结构体需要:name(字符串)、uri(指向 JSON 元数据的字符串)、sellerFeeBasisPoints(0-10000,或铸造到集合时省略以从其 Royalties 插件继承)、collection(公钥或 none)、creators(创作者对象数组;继承版税时必须为空)。

cNFT 可以从 MPL-Core 集合继承版税吗?

可以。使用 coreCollection 铸造时,省略 metadata.sellerFeeBasisPoints 并将 metadata.creators 留空。SDK 在叶子上存储 SELLER_FEE_BASIS_POINTS_INHERIT(65535)。集合必须具有 Royalties 插件。请参阅从集合继承版税。

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
SELLER_FEE_BASIS_POINTS_INHERITSentinel value 65535 (0xffff) stored on-chain to indicate royalties are inherited from the MPL-Core collection
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