概览

集合管理是 CreateKit 的核心。本指南涵盖了使用 BaseMint 协议创建、配置和管理 NFT 集合所需了解的所有信息。

集合元数据结构

每个集合都需要特定的元数据来定义其特征:

必需参数

name
string
您的 NFT 集合名称(例如,“Bored Ape Yacht Club”)
symbol
string
您的集合符号/股票代码(例如,“BAYC”)
creator
0x${string}
集合创建者的以太坊地址
gameOwner
0x${string}
游戏所有者的以太坊地址(可以与创建者相同)

可选参数

maxSupply
bigint
default:"10000n"
可铸造的最大代币数量
mintPrice
bigint
default:"0n"
每个代币的价格(以 wei 为单位)(对于 ETH 值使用 parseEther())
maxPerWallet
bigint
default:"100n"
每个钱包可铸造的最大代币数量
isWhitelistEnabled
boolean
default:"false"
是否启用了仅白名单铸造
startTime
bigint
default:"0n"
铸造开始的 Unix 时间戳(0 = 立即)
endTime
bigint
default:"BigInt(Date.now() / 1000 + 86400 * 365 * 100)"
铸造结束的 Unix 时间戳
tokenStandard
'ERC721' | 'ERC1155'
default:"'ERC721'"
使用的代币标准
chainId
number
default:"1993"
链 ID(1993 = B3 测试网,8333 = B3 主网)

创建集合

基础集合

基础集合创建
import { CollectionManager, b3Testnet } from '@b3dotfun/basemint'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const publicClient = createPublicClient({
  chain: b3Testnet,
  transport: http()
})

const walletClient = createWalletClient({
  chain: b3Testnet,
  transport: http(),
  account
})

const collectionManager = new CollectionManager(publicClient)

// 定义基础集合
const basicCollection = {
  name: "My Art Collection",
  symbol: "MAC",
  creator: account.address,
  gameOwner: account.address,
  description: "一系列数字艺术作品",
  image: "https://example.com/collection-image.png"
}

// 生成创建者签名
const creatorSignature = await collectionManager.generateCreatorSignature(
  walletClient,
  basicCollection
)

高级集合配置

高级集合设置
import { parseEther } from 'viem'

const advancedCollection = {
  // 必需
  name: "Premium Gaming Items",
  symbol: "PGI",
  creator: account.address,
  gameOwner: "0x1234567890123456789012345678901234567890", // 不同的游戏所有者
  
  // 供应量和定价
  maxSupply: 5000n,
  mintPrice: parseEther("0.01"), // 0.01 ETH
  maxPerWallet: 5n,
  
  // 时间控制
  startTime: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1小时后开始
  endTime: BigInt(Math.floor(Date.now() / 1000) + 86400 * 7), // 7天后结束
  
  // 白名单配置
  isWhitelistEnabled: true,
  whitelistMerkleRoot: "0x..." as `0x${string}`,
  
  // 元数据
  description: "为高级玩家提供的独家游戏物品",
  image: "https://example.com/premium-collection.png",
  external_url: "https://mygame.com/premium-items",
  animation_url: "https://example.com/collection-animation.mp4",
  
  // 集合属性
  attributes: [
    { trait_type: "Category", value: "Gaming" },
    { trait_type: "Rarity", value: "Premium" },
    { trait_type: "Edition", value: "First" }
  ],
  
  // 技术
  tokenStandard: "ERC1155" as const,
  chainId: 1993
}

代币标准

CreateKit 支持 ERC721 和 ERC1155 标准:
const erc721Collection = {
  name: "Unique Art Pieces",
  symbol: "UAP",
  creator: account.address,
  gameOwner: account.address,
  tokenStandard: "ERC721" as const,
  maxSupply: 1000n, // 每个代币都是独一无二的
  description: "独一无二的数字艺术作品"
}

// ERC721 铸造(数量始终为 1)
const collection721 = collectionManager.createCollection(
  predictedAddress,
  "ERC721"
)

await collection721.mint(
  walletClient,
  1n, // 对于 ERC721 始终为 1
  undefined, // 元数据 URI
  mintPrice,
  proof
)

元数据管理

集合级元数据

集合元数据
const collectionMetadata = {
  name: "My Collection",
  description: "一系列精彩的数字资产",
  image: "https://example.com/collection-image.png",
  external_url: "https://mywebsite.com/collection",
  
  // 市场背景和横幅
  background_color: "ffffff",
  banner_image_url: "https://example.com/banner.png",
  
  // 集合属性
  attributes: [
    { trait_type: "Theme", value: "Fantasy" },
    { trait_type: "Artist", value: "Digital Creator" }
  ]
}

代币级元数据

CreateKit 根据您的集合设置自动生成代币元数据:
import { NFTMetadataManager, MediaType } from '@b3dotfun/basemint'

// 为不同的媒体类型生成元数据
const artworkMetadata = NFTMetadataManager.generateNFTMetadata(
  collectionMetadata,
  MediaType.ARTWORK
)

const model3dMetadata = NFTMetadataManager.generateNFTMetadata(
  collectionMetadata,
  MediaType.MODEL_3D
)

const videoMetadata = NFTMetadataManager.generateNFTMetadata(
  collectionMetadata,
  MediaType.VIDEO
)

// 转换为 JSON
const metadataJson = NFTMetadataManager.generateJSON(artworkMetadata)
console.log(metadataJson)

集合验证

CreateKit 为集合参数提供内置验证:
参数验证
import { validateCollectionMetadata } from '@b3dotfun/basemint'

try {
  // 验证集合元数据
  const validation = validateCollectionMetadata(collectionMetadata)
  
  if (!validation.isValid) {
    console.error("验证错误:", validation.errors)
    return
  }
  
  console.log("✅ 集合元数据有效")
  
  // 继续生成签名
  const signature = await collectionManager.generateCreatorSignature(
    walletClient,
    collectionMetadata
  )
} catch (error) {
  console.error("验证失败:", error)
}

地址预测

CreateKit 的一个关键特性是确定性地址预测:
地址预测
// 首先生成创建者签名
const creatorSignature = await collectionManager.generateCreatorSignature(
  walletClient,
  collectionMetadata
)

// 预测集合地址
const predictedAddress = collectionManager.predictCollectionAddress(
  collectionMetadata,
  creatorSignature
)

console.log(`集合将部署在:${predictedAddress}`)

// 现在您可以在部署前使用此地址
// 用于市场集成、前端显示等。

集合管理操作

检查集合状态

集合状态
const collection = collectionManager.createCollection(
  predictedAddress,
  "ERC721"
)

// 检查集合是否已部署
const isDeployed = await collection.isDeployed()
console.log(`已部署:${isDeployed}`)

// 获取集合信息(仅在部署后有效)
if (isDeployed) {
  const info = await collection.getCollectionInfo()
  console.log("集合信息:", {
    name: info.name,
    symbol: info.symbol,
    totalSupply: info.totalSupply.toString(),
    maxSupply: info.maxSupply.toString(),
    mintPrice: info.mintPrice.toString(),
    maxPerWallet: info.maxPerWallet.toString()
  })
}

更新集合设置

大多数集合参数在部署后无法更改。请仔细规划您的集合配置。
部署后管理
// 部署后只能进行某些操作

// 检查当前铸造价格(如果实现了动态定价)
const currentPrice = await collection.getCurrentMintPrice()

// 检查当前是否可以铸造
const isMintingActive = await collection.isMintingActive()

// 获取剩余供应量
const remainingSupply = await collection.getRemainingSupply()

console.log({
  currentPrice: currentPrice.toString(),
  isMintingActive,
  remainingSupply: remainingSupply.toString()
})

最佳实践

1. 集合规划

供应策略

  • 根据用例设置适当的最大供应量
  • 考虑未来需求和稀缺性
  • 为增长或特别版留出空间

定价策略

  • 研究类似集合以参考定价
  • 考虑燃气费用和交易费用
  • 为不同的市场条件规划

2. 元数据质量

高质量元数据
const qualityCollection = {
  name: "Professional Art Collection",
  symbol: "PAC",
  creator: account.address,
  gameOwner: account.address,
  
  // 高质量描述
  description: "精选的专业数字艺术作品集,展示当代主题和创新技术。",
  
  // 专业图像(最小 640x640px)
  image: "https://example.com/high-res-collection-image.png",
  
  // 全面的属性以提高可发现性
  attributes: [
    { trait_type: "Art Style", value: "Contemporary" },
    { trait_type: "Medium", value: "Digital" },
    { trait_type: "Artist Verification", value: "Verified" },
    { trait_type: "Edition Type", value: "Limited" }
  ],
  
  // 外部链接以增加可信度
  external_url: "https://professionalartist.com/collection"
}

3. 安全考虑

故障排除

下一步

现在您已经了解了集合管理,探索这些相关主题: