Ikhtisar

Halaman ini menyediakan contoh nyata yang komprehensif tentang implementasi CreateKit dalam berbagai skenario. Setiap contoh mencakup kode lengkap, penanganan kesalahan, dan praktik terbaik.

Koleksi NFT Dasar

Koleksi seni sederhana dengan penambangan gratis:
Koleksi Seni Dasar
import { 
  CollectionManager, 
  BaseMintStorage, 
  b3Testnet 
} from '@b3dotfun/basemint'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

async function createBasicArtCollection() {
  // Setup clients
  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
  })

  // Initialize services
  const collectionManager = new CollectionManager(publicClient)
  const storage = new BaseMintStorage({ baseUrl: 'https://api.basemint.fun' })

  // Define collection
  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, // Free minting
    maxPerWallet: 5n,
    tokenStandard: "ERC721" as const,
    chainId: 1993
  }

  try {
    console.log("🎨 Creating art collection...")

    // Generate creator signature
    const creatorSignature = await collectionManager.generateCreatorSignature(
      walletClient,
      artCollection
    )

    // Predict address
    const predictedAddress = collectionManager.predictCollectionAddress(
      artCollection,
      creatorSignature
    )
    console.log(`📍 Collection address: ${predictedAddress}`)

    // Submit to storage
    await storage.submitCollection(artCollection, creatorSignature)
    console.log("✅ Collection metadata stored")

    // Deploy and mint first 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(`🎉 Collection deployed and first NFT minted: ${mintTx}`)
    return { collection, predictedAddress, mintTx }

  } catch (error) {
    console.error("❌ Failed to create art collection:", error)
    throw error
  }
}

// Usage
createBasicArtCollection()
  .then(result => console.log("Collection created successfully:", result))
  .catch(error => console.error("Creation failed:", error))

Koleksi Gaming dengan Whitelist

Koleksi gaming dengan akses whitelist bertingkat:

Platform Multi-Koleksi

Platform yang mengelola beberapa koleksi:

Integrasi Marketplace

Mengintegrasikan CreateKit dengan marketplace:
Integrasi Marketplace
import { 
  CollectionManager,
  BaseMintStorage,
  RewardTracker 
} from '@b3dotfun/basemint'

class NFTMarketplace {
  private storage: BaseMintStorage
  private collectionManager: CollectionManager
  private rewardTracker: RewardTracker

  constructor(publicClient: any) {
    this.storage = new BaseMintStorage({ baseUrl: 'https://api.basemint.fun' })
    this.collectionManager = new CollectionManager(publicClient)
    this.rewardTracker = new RewardTracker(publicClient)
  }

  // Discover collections for marketplace display
  async discoverCollections(filters?: {
    category?: string
    minSupply?: number
    maxPrice?: string
    deployed?: boolean
  }) {
    const queryFilters: any = {}
    
    if (filters?.deployed !== undefined) {
      queryFilters.deployed = filters.deployed
    }

    const collections = await this.storage.queryCollections({
      ...queryFilters,
      limit: 50,
      sortBy: "createdAt",
      sortOrder: "desc"
    })

    // Enrich with on-chain data for deployed collections
    const enrichedCollections = await Promise.all(
      collections.collections.map(async (collection) => {
        if (collection.isDeployed) {