몇 분 만에 CreateKit으로 첫 NFT 컬렉션을 만드세요
import {
CollectionManager,
RewardTracker,
BaseMintStorage,
b3Testnet
} from '@b3dotfun/basemint'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
// 클라이언트 초기화
const publicClient = createPublicClient({
chain: b3Testnet,
transport: http()
})
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const walletClient = createWalletClient({
chain: b3Testnet,
transport: http(),
account
})
// CreateKit 서비스 초기화
const collectionManager = new CollectionManager(publicClient)
const rewardTracker = new RewardTracker(publicClient)
const storage = new BaseMintStorage({
baseUrl: 'https://api.basemint.fun'
})
const collectionMetadata = {
// 필수 파라미터
name: "My First Collection",
symbol: "MFC",
creator: account.address,
gameOwner: account.address, // 다른 주소일 수 있음
// 선택적 파라미터
maxSupply: 1000n,
mintPrice: 0n, // 무료 민팅
maxPerWallet: 10n,
description: "B3에서의 나의 첫 NFT 컬렉션",
image: "https://example.com/collection-image.png",
// 타이밍
startTime: 0n, // 즉시 시작
endTime: BigInt(Math.floor(Date.now() / 1000) + 86400 * 30), // 30일
// 토큰 표준
tokenStandard: "ERC721" as const,
chainId: 1993 // B3 테스트넷
}
// 생성자 서명 생성
const creatorSignature = await collectionManager.generateCreatorSignature(
walletClient,
collectionMetadata
)
// 컬렉션 주소 예측
const predictedAddress = collectionManager.predictCollectionAddress(
collectionMetadata,
creatorSignature
)
console.log(`📍 예측된 컬렉션 주소: ${predictedAddress}`)
try {
await storage.submitCollection(collectionMetadata, creatorSignature)
console.log("✅ 컬렉션 메타데이터가 성공적으로 저장되었습니다")
} catch (error) {
console.error("❌ 컬렉션 저장 실패:", error)
}
// 배포자 서명 생성
const deployerSignature = await collectionManager.generateDeployerSignature(
walletClient,
predictedAddress
)
// 컬렉션 인스턴스 생성
const collection = collectionManager.createCollection(
predictedAddress,
collectionMetadata.tokenStandard
)
// 한 번의 트랜잭션으로 배포 및 첫 NFT 민팅
const mintTx = await collection.mint(
walletClient,
1n, // 수량
undefined, // 메타데이터 URI (baseURI 사용)
0n, // 민팅 가격
[], // 화이트리스트 증명 (공개 민팅을 위한 빈 배열)
creatorSignature,
deployerSignature
)
console.log(`🎉 컬렉션이 배포되었고 첫 NFT가 민팅되었습니다!`)
console.log(`📋 트랜잭션 해시: ${mintTx}`)
// 컬렉션이 배포되었는지 확인
const isDeployed = await collection.isDeployed()
console.log(`🏭 컬렉션 배포됨: ${isDeployed}`)
// 컬렉션 정보 가져오기
const info = await collection.getCollectionInfo()
console.log("📊 컬렉션 정보:", {
name: info.name,
symbol: info.symbol,
totalSupply: info.totalSupply.toString(),
maxSupply: info.maxSupply.toString()
})
// 토큰 소유권 확인
const balance = await collection.balanceOf(account.address)
console.log(`💰 당신의 토큰 잔액: ${balance.toString()}`)
// 보상을 위한 에스크로 계약 가져오기
const escrowAddress = collectionManager.getEscrowAddress()
// 이 컬렉션에 대한 보상 추적
const collectionRewards = await rewardTracker.getCollectionRewards(
escrowAddress,
predictedAddress
)
console.log("💎 컬렉션 보상:", {
totalRewards: collectionRewards.totalRewards.toString(),
unclaimedRewards: collectionRewards.unclaimedRewards.toString(),
totalMints: collectionRewards.totalMints.toString()
})
// 개별 수령인 보상 가져오기
const creatorRewards = await rewardTracker.getRecipientRewards(
escrowAddress,
predictedAddress,
"CREATOR",
account.address
)
console.log(`🎨 창작자 보상: ${creatorRewards.toString()}`)
Complete quickstart.ts
import {
CollectionManager,
RewardTracker,
BaseMintStorage,
b3Testnet
} from '@b3dotfun/basemint'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
async function quickstart() {
// 클라이언트 초기화
const publicClient = createPublicClient({
chain: b3Testnet,
transport: http()
})
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const walletClient = createWalletClient({
chain: b3Testnet,
transport: http(),
account
})
// CreateKit 서비스 초기화
const collectionManager = new CollectionManager(publicClient)
const rewardTracker = new RewardTracker(publicClient)
const storage = new BaseMintStorage({
baseUrl: 'https://api.basemint.fun'
})
// 1단계: 컬렉션 메타데이터 생성
const collectionMetadata = {
name: "My First Collection",
symbol: "MFC",
creator: account.address,
gameOwner: account.address,
maxSupply: 1000n,
mintPrice: 0n,
maxPerWallet: 10n,
description: "B3에서의 나의 첫 NFT 컬렉션",
image: "https://example.com/collection-image.png",
startTime: 0n,
endTime: BigInt(Math.floor(Date.now() / 1000) + 86400 * 30),
tokenStandard: "ERC721" as const,
chainId: 1993
}
// 2단계: 서명 생성
const creatorSignature = await collectionManager.generateCreatorSignature(
walletClient,
collectionMetadata
)
const predictedAddress = collectionManager.predictCollectionAddress(
collectionMetadata,
creatorSignature
)
console.log(`📍 예측된 컬렉션 주소: ${predictedAddress}`)
// 3단계: 저장소에 제출
try {
await storage.submitCollection(collectionMetadata, creatorSignature)
console.log("✅ 컬렉션 메타데이터가 성공적으로 저장되었습니다")
} catch (error) {
console.error("❌ 컬렉션 저장 실패:", error)
return
}
// 4단계: 배포 및 민팅
const deployerSignature = await collectionManager.generateDeployerSignature(
walletClient,
predictedAddress
)
const collection = collectionManager.createCollection(
predictedAddress,
collectionMetadata.tokenStandard
)
const mintTx = await collection.mint(
walletClient,
1n,
undefined,
0n,
[],
creatorSignature,
deployerSignature
)
console.log(`🎉 컬렉션이 배포되었고 첫 NFT가 민팅되었습니다!`)
console.log(`📋 트랜잭션 해시: ${mintTx}`)
// 5단계: 배포 확인
const isDeployed = await collection.isDeployed()
console.log(`🏭 컬렉션 배포됨: ${isDeployed}`)
// 6단계: 보상 추적
const escrowAddress = collectionManager.getEscrowAddress()
const collectionRewards = await rewardTracker.getCollectionRewards(
escrowAddress,
predictedAddress
)
console.log("💎 컬렉션 보상:", {
totalRewards: collectionRewards.totalRewards.toString(),
unclaimedRewards: collectionRewards.unclaimedRewards.toString(),
totalMints: collectionRewards.totalMints.toString()
})
}
// 퀵스타트 실행
quickstart().catch(console.error)
quickstart.ts
로 저장하고 실행하세요:
npx tsx quickstart.ts
📍 예측된 컬렉션 주소: 0x1234567890abcdef...
✅ 컬렉션 메타데이터가 성공적으로 저장되었습니다
🎉 컬렉션이 배포되었고 첫 NFT가 민팅되었습니다!
📋 트랜잭션 해시: 0xabcdef1234567890...
🏭 컬렉션 배포됨: true
💎 컬렉션 보상: {
totalRewards: "1000000000000000000",
unclaimedRewards: "1000000000000000000",
totalMints: "1"
}
트랜잭션 실패
저장소 제출 실패
컬렉션이 이미 존재함