概览

此页面提供了在各种场景中实现 CreateKit 的全面、真实世界的示例。每个示例都包括完整的代码、错误处理和最佳实践。

基础 NFT 收藏

一个简单的艺术收藏,免费铸造:
基础艺术收藏
import { 
  CollectionManager, 
  BaseMintStorage, 
  b3Testnet 
} from '@b3dotfun/basemint'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

async function createBasicArtCollection() {
  // 设置客户端
  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 storage = new BaseMintStorage({ baseUrl: 'https://api.basemint.fun' })

  // 定义收藏
  const artCollection = {
    name: "Digital Art Gallery",
    symbol: "DAG", 
    creator: account.address,
    gameOwner: account.address,
    description: "A curated collection of digital artworks",
    image: "https://example.com/art-collection.png",
    maxSupply: 1000n,
    mintPrice: 0n, // 免费铸造
    maxPerWallet: 5n,
    tokenStandard: "ERC721" as const,
    chainId: 1993
  }

  try {
    console.log("🎨 正在创建艺术收藏...")

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

    // 预测地址
    const predictedAddress = collectionManager.predictCollectionAddress(
      artCollection,
      creatorSignature
    )
    console.log(`📍 收藏地址: ${predictedAddress}`)

    // 提交到存储
    await storage.submitCollection(artCollection, creatorSignature)
    console.log("✅ 收藏元数据已存储")

    // 部署并铸造第一个 NFT
    const deployerSignature = await collectionManager.generateDeployerSignature(
      walletClient,
      predictedAddress
    )

    const collection = collectionManager.createCollection(predictedAddress, "ERC721")
    const mintTx = await collection.mint(
      walletClient,
      1n,
      undefined,
      0n,
      [],
      creatorSignature,
      deployerSignature
    )

    console.log(`🎉 收藏已部署并铸造了第一个 NFT: ${mintTx}`)
    return { collection, predictedAddress, mintTx }

  } catch (error) {
    console.error("❌ 创建艺术收藏失败:", error)
    throw error
  }
}

// 使用
createBasicArtCollection()
  .then(result => console.log("收藏成功创建:", result))
  .catch(error => console.error("创建失败:", error))

带白名单的游戏收藏

一个带有分级白名单访问的游戏收藏:

多收藏平台

管理多个收藏的平台:

市场