在你的網站上鑄造
使用你自己的 EVM 錢包連接器和公開 ABI。KurvDrop 的鑄造是一個 ERC-20 操作,不是用 ETH 付款的 payable 鑄造。ETH 用來支付網路 Gas。免費鑄造階段仍可能收取系列的服務費,所以請以報價為準,不要假設費用為零。
這個範例處理的是沒有拍賣模組的公開階段,並把付款上限設為精確的報價。它使用訪客自己提供的瀏覽器錢包,絕不使用伺服器私鑰。在執行授權和鑄造寫入之前,請先向買家顯示總額、額外的代幣費用和所在的鏈,並取得他們的確認。
import { createPublicClient, createWalletClient, custom, erc20Abi, http, zeroAddress, zeroHash,} from 'viem';import { baseSepolia } from 'viem/chains';
const api = 'https://testnet.kurv.fun';const { abi } = await fetch(`${api}/api/v1/contracts/kurvdrop`).then(r => r.json());const publicClient = createPublicClient({ chain: baseSepolia, transport: http() });const walletClient = createWalletClient({ chain: baseSepolia, transport: custom(window.ethereum) });const [account] = await walletClient.requestAddresses();await walletClient.switchChain({ id: baseSepolia.id });
// Woof Pack, verified in KURV's Base Sepolia catalog.const address = '0x8354d02d8022f455db9acb235c6f6655c8adabd3';const { collection: live } = await fetch( `${api}/api/v1/collections/84532/${address}`).then(r => r.json());if (live.contract_type !== 'KurvDrop' || live.mint.active_phase_id === null) { throw new Error('No public mint phase is available.');}const phaseId = BigInt(live.mint.active_phase_id);const quantity = 1n;const phase = await publicClient.readContract({ address, abi, functionName: 'getPhase', args: [phaseId] });if (phase.module !== zeroAddress || phase.merkleRoot !== zeroHash) { throw new Error('This example supports only public phases without an auction module.');}const paymentToken = await publicClient.readContract({ address, abi, functionName: 'paymentToken' });const [maxTotalCost] = await publicClient.readContract({ address, abi, functionName: 'quoteMint', args: [phaseId, quantity] });
// Display these amounts using each token's on-chain decimals and symbol.const required = new Map([[paymentToken.toLowerCase(), maxTotalCost]]);if (phase.token !== zeroAddress && phase.tokenPrice > 0n) { const token = phase.token.toLowerCase(); required.set(token, (required.get(token) ?? 0n) + phase.tokenPrice * quantity);}
// Run only after the buyer reviews and confirms the displayed amounts.for (const [token, amount] of required) { const allowance = await publicClient.readContract({ address: token, abi: erc20Abi, functionName: 'allowance', args: [account, address] }); if (allowance >= amount) continue; // Reset an existing allowance for tokens requiring zero before a new approval. if (allowance > 0n) { const reset = await walletClient.writeContract({ account, address: token, abi: erc20Abi, functionName: 'approve', args: [address, 0n] }); await publicClient.waitForTransactionReceipt({ hash: reset }); } const approved = await walletClient.writeContract({ account, address: token, abi: erc20Abi, functionName: 'approve', args: [address, amount] }); await publicClient.waitForTransactionReceipt({ hash: approved });}
// Exact quote ceiling: if the required price increased, simulation/mint refuses.const { request } = await publicClient.simulateContract({ account, address, abi, functionName: 'mint', args: [phaseId, quantity, 0n, [], maxTotalCost, zeroAddress],});const hash = await walletClient.writeContract(request);const receipt = await publicClient.waitForTransactionReceipt({ hash });if (receipt.status !== 'success') throw new Error('Mint did not complete.');如果是白名單階段,請透過 KURV 現有的證明流程,取得買家錢包的額度和 Merkle 證明,並把它們當作鑄造的第三和第四個參數傳入。私人階段絕對不能用空的證明代替。錢包上限、階段總量、暫停、拍賣保留和總費用都由合約強制執行;送出之前,模擬必須成功。降價拍賣和單件拍賣使用它們自己的銷售模組,不是一般的內嵌 mint 階段;在你串接並驗證該模組的 ABI 和結算流程之前,請使用官方頁面。
最後一個鑄造參數是推薦人錢包地址,不是追蹤字串。在你有意串接已部署系列的推薦條款之前,預設使用 zeroAddress。實際的費用分配由合約決定;光是加上連結代碼,本身並不會產生佣金。市場轉售使用市場合約和簽署過的訂單,而不是這裡示範的初次鑄造呼叫。
關於系列回應的結構,請參閱公開 API。如果需要現成的小工具,請使用系列嵌入。合約權限、費用和系列本身的條款仍然適用;請參閱費用和風險與免責聲明。
此處內容均不構成財務建議。在鑄造、購買或賣回之前,請先閱讀風險與免責聲明。返回 kurv.fun。隱私權政策。使用條款。 。