diff --git a/packages/nextjs/app/simpleMint/page.tsx b/packages/nextjs/app/simpleMint/page.tsx index 87b54ca..cb88656 100644 --- a/packages/nextjs/app/simpleMint/page.tsx +++ b/packages/nextjs/app/simpleMint/page.tsx @@ -78,17 +78,20 @@ const SimpleMint: NextPage = () => { const handleMPaidMint = async () => { const notificationId = notification.loading("Uploading to IPFS"); + try { const uploadedItem = await addToIPFS(yourJSON); - notification.remove(notificationId); notification.success("Metadata uploaded to IPFS"); // Log IPFS path before sending to contract console.log("IPFS Path:", uploadedItem.path); - // Mint the NFT - await writeContractAsync({ + if (!connectedAddress) { + throw new Error("No connected address found."); + } + + const contractResponse = await writeContractAsync({ functionName: "startCollection", args: [ collectionName, @@ -100,13 +103,28 @@ const SimpleMint: NextPage = () => { ], }); + if (!contractResponse) { + throw new Error("Contract response is null or undefined."); + } + + console.log("Contract Response:", contractResponse); notification.success("Collection started successfully!"); } catch (error) { notification.remove(notificationId); - console.error("Error during minting:", error); - // Log the error and notify the user - notification.error("Minting failed, please try again."); + // Type guard to narrow the type of 'error' + if (error instanceof Error) { + console.error("Error during minting:", error); + + if (error.message.includes("gasLimit")) { + notification.error("Minting failed due to gas limit issue, please check your network and wallet setup."); + } else { + notification.error("Minting failed, please try again."); + } + } else { + console.error("An unknown error occurred:", error); + notification.error("An unknown error occurred."); + } } }; @@ -398,7 +416,7 @@ const SimpleMint: NextPage = () => {
{isGaslessMinting ? ( ) : (