功能

创建 Core Collection

Last updated April 8, 2026

createCollection 指令在 Solana 上创建一个带有名称、元数据 URI 和可选插件的新 Core Collection 账户。

学习内容

  • 使用名称和 URI 创建简单的 Collection
  • 创建附带 Royalties 插件的 Collection
  • 处理常见的创建错误

Summary

createCollection 部署一个新的 Collection 账户,将 Core Asset 组织在共享元数据和插件下。

  • 需要一个新的密钥对作为 collection 地址 — 重用现有地址会失败
  • 创建时可以指定可选的插件
  • 需要约 0.0015 SOL 作为租金
  • 默认情况下付款方成为 updateAuthority

Quick Start

  1. 安装:npm install @metaplex-foundation/mpl-core @metaplex-foundation/umi
  2. 上传合集元数据 JSON 以获取 URI
  3. 调用 createCollection(umi, { collection, name, uri })
  4. 创建 Asset 时传入 collection 地址

跳转至: 简单 Collection · 带插件 · 错误处理

前提条件

  • 已配置签名者和 RPC 连接的 Umi — 参见 JavaScript SDK
  • 用于交易费用的 SOL(每个 Collection 约 0.002 SOL)
  • 已上传到 Arweave 或 IPFS 的包含合集图片和名称的元数据 JSON

创建简单的 Collection

createCollection 需要 name、元数据 uri 以及作为 collection 签名者的新密钥对。

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { createCollection } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4import { generateSigner } from '@metaplex-foundation/umi'
5
6// Initialize UMI
7const umi = createUmi('https://api.devnet.solana.com')
8 .use(mplCore())
9
10// Generate a new keypair for the collection
11const collectionSigner = generateSigner(umi)
12
13// Create a new Collection
14await createCollection(umi, {
15 collection: collectionSigner,
16 name: 'My Collection',
17 uri: 'https://example.com/collection.json',
18}).sendAndConfirm(umi)
19
20console.log('Collection created:', collectionSigner.publicKey)

collection 参数每次必须是新的密钥对。重用现有账户地址会导致 Collection account already exists 错误。

创建带插件的 Collection

createCollection 传入 plugins 数组以在创建时附加插件。以下示例附加了 Royalties 插件

创建带 Royalties 插件的 Core Collection

create-collection-with-royalties.ts
import { generateSigner, publicKey } from '@metaplex-foundation/umi'
import { createCollection, ruleSet } from '@metaplex-foundation/mpl-core'
const collectionSigner = generateSigner(umi)
const creator1 = publicKey('11111111111111111111111111111111')
const creator2 = publicKey('22222222222222222222222222222222')
await createCollection(umi, {
collection: collectionSigner,
name: 'My NFT',
uri: 'https://example.com/my-nft.json',
plugins: [
{
type: 'Royalties',
basisPoints: 500,
creators: [
{ address: creator1, percentage: 20 },
{ address: creator2, percentage: 80 },
],
ruleSet: ruleSet('None'),
},
],
}).sendAndConfirm(umi)

常见错误

Collection account already exists

该 collection 密钥对已在此网络上使用过。每次生成新的签名者:

const collectionSigner = generateSigner(umi) // 必须是唯一的密钥对

Insufficient funds

付款方钱包需要约 0.002 SOL。在开发网上充值:

solana airdrop 1 <WALLET_ADDRESS> --url devnet

Notes

  • 创建时添加的插件可以在之后使用 updateCollectionPlugin 更新 — 参见更新 Collection
  • updateAuthority 默认为付款方 — 传入显式的 updateAuthority 来设置不同的账户
  • 所有可用于 Asset 的插件也可以应用于 Collection — 参见插件概述

Quick Reference

项目
InstructionCreateCollectionV1
JS 函数createCollection
必填账户collection(新密钥对)、payer
可选账户updateAuthoritysystemProgram
必填参数nameuri
可选参数plugins
租金费用约 0.0015 SOL
源码GitHub
Previous
概述