0

I'm using @metaplex-foundation/umi version 0.8.2. I upgraded from 0.7.14 because the older version doesn't install correctly anymore(get error missing serializers module) with the new version my mint functions throw the error: Mint Error TypeError: Cannot read properties of undefined (reading 'length'). I think it's how I have the candy machine set in state but no idea how to fix it.

Heres the mint function followed by the entire code if needed:

  const payMintButtonClicked = async () => {
    setIsUserMinting(true);
    try {
      if (candyMachine?.publicKey) {
        const nftMint = generateSigner(umi);
    const pMint = await transactionBuilder()
      .add(setComputeUnitLimit(umi, { units: 800_000 }))
      .add(
        mintV2(umi, {
          candyMachine: candyMachine.publicKey,
          nftMint,
          collectionMint: candyMachine.collectionMint,
          collectionUpdateAuthority: owner,
          group: some("pay"),
          mintArgs: {
            tokenPayment: some({
                mint: tokenMint,
                destinationAta: destinationAta,
            }),
          },
          tokenStandard: TokenStandard.ProgrammableNonFungible,
        })
      )
      .sendAndConfirm(umi);

Here's my entire code to help:

import {
  some,
  generateSigner,
  transactionBuilder,
  publicKey
} from "@metaplex-foundation/umi";
import {
  CandyMachine,
  fetchCandyMachine,
  mintV2,
  getMerkleProof,
  getMerkleRoot,
  route
} from "@metaplex-foundation/mpl-candy-machine";
import { TokenStandard } from "@metaplex-foundation/mpl-token-metadata";
import { setComputeUnitLimit } from "@metaplex-foundation/mpl-essentials";
import { allowList, saibaCandy } from "../../const/contractAddresses";
import { CircularProgress, Container } from "@mui/material";
import Button from "@mui/material/Button";
import Grid from "@mui/material/Grid";
import Paper from "@mui/material/Paper";
import Typography from "@mui/material/Typography";
import { SolanaMobileWalletAdapterWalletName } from "@solana-mobile/wallet-adapter-mobile";
import { useWallet } from "@solana/wallet-adapter-react";
import {
  MediaRenderer
} from "@thirdweb-dev/react";
import { useEffect, useState } from "react";
import styles from '../../styles/mint.module.css';
import { useSnackbar } from "notistack";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { mplCandyMachine } from "@metaplex-foundation/mpl-candy-machine";
import { walletAdapterIdentity } from '@metaplex-foundation/umi-signer-wallet-adapters';


const SaibaMint = () => {
  const wallet = useWallet();
  const [pageLoading, setPageLoading] = useState<boolean>(true);
  const [candyMachine, setCandyMachine] = useState<CandyMachine | undefined>();
  const [isUserMinting, setIsUserMinting] = useState(false);
  const tokenMint = publicKey("address");
  const owner = publicKey("address");
  const destinationAta = publicKey("address");
  const { enqueueSnackbar } = useSnackbar();
  const umi = createUmi("rpc http")
  .use(walletAdapterIdentity(wallet))
  .use(mplCandyMachine());

  const getCandyMachine = async () => {
    setPageLoading(true);
    try {
      const cmPubkey = publicKey(
        candyAddress ?? ""
      );
      const candyMachine = await fetchCandyMachine(umi, cmPubkey);
      if (!candyMachine) throw new Error("No Candymachine at address");
      setCandyMachine(candyMachine);
    } catch (error) {
      console.log("Fetching CM Error", error);
      enqueueSnackbar(
        "Fetching CM Error: Check console logs for more details",
        {
          variant: "error",
          anchorOrigin: { vertical: "top", horizontal: "right" },
        }
      );
    }
  
    setPageLoading(false);
  };
  
  useEffect(() => {
    getCandyMachine();
  }, []);

  const merkleButtonClicked = async () => {
    try {
      if (candyMachine?.publicKey) {
        const proof = await route(umi, {
            candyMachine: candyMachine?.publicKey,
            guard: "allowList",
            group: some("alist"),
            routeArgs: {
                path: "proof",
                merkleRoot: getMerkleRoot(allowList),
                merkleProof: getMerkleProof(allowList, publicKey(umi.identity)),
            }
        }).sendAndConfirm(umi);
    
      console.log( "you're in!!!", proof )
      enqueueSnackbar(
        "you're in!!!",
        {
          variant: "success",
          anchorOrigin: { vertical: "top", horizontal: "right" },
        }
      );
      }
    } catch (error) {
      console.error("Proof Error", error);
      enqueueSnackbar("But my girlfriend is in there!?!... a lot of girlfriends are in here.", {
        variant: "error",
        anchorOrigin: { vertical: "top", horizontal: "right" },
      });
    }
  };

    const getAllowMintButtonContent = () => {
      if (!candyMachine) {
        return "Loading...";
      }
  
      if (isUserMinting) {
        return "Minting in progress..";
      } else if (candyMachine.itemsRedeemed === BigInt(10000)) {
        return "Sold out";
      } else {
        return <img
        style={{
          maxHeight: "75px",
        }}
        src="/images/rx7.png"
        alt="car"
      />;
      }
    };

  const allowMintButtonClicked = async () => {
    setIsUserMinting(true);
    try {
      if (candyMachine?.publicKey) {
        const nftMint = generateSigner(umi);
    const aMint = await transactionBuilder()
      .add(setComputeUnitLimit(umi, { units: 800_000 }))
      .add(
        mintV2(umi, {
          candyMachine: candyMachine.publicKey,
          nftMint,
          collectionMint: candyMachine.collectionMint,
          collectionUpdateAuthority: owner,
          group: some("alist"),
          mintArgs: {
            allowList: some({ merkleRoot: getMerkleRoot(allowList) }),
            mintLimit: some({ id: 1 }),
            solPayment: some({ destination: candyMachine.authority }),
          },
          tokenStandard: TokenStandard.ProgrammableNonFungible,
        })
      )
      .sendAndConfirm(umi);
    
      console.log( "Mint Success!!!", aMint )
      enqueueSnackbar(
        "Mint Success!!!",
        {
          variant: "success",
          anchorOrigin: { vertical: "top", horizontal: "right" },
        }
      );
      }
    } catch (error) {
      console.error("Mint Error", error);
      enqueueSnackbar("Mint Error: Check console logs for more details", {
        variant: "error",
        anchorOrigin: { vertical: "top", horizontal: "right" },
      });
    }
    setIsUserMinting(false);
  };

  const getPayMintButtonContent = () => {
    if (!candyMachine) {
      return "Loading...";
    }

    if (isUserMinting) {
      return "Minting in progress..";
    } else if (candyMachine.itemsRedeemed === BigInt(10000)) {
      return "Sold out";
    } else {
      return "USDC";
    }
  };

  const payMintButtonClicked = async () => {
    setIsUserMinting(true);
    try {
      if (candyMachine?.publicKey) {
        const nftMint = generateSigner(umi);
    const pMint = await transactionBuilder()
      .add(setComputeUnitLimit(umi, { units: 800_000 }))
      .add(
        mintV2(umi, {
          candyMachine: candyMachine.publicKey,
          nftMint,
          collectionMint: candyMachine.collectionMint,
          collectionUpdateAuthority: owner,
          group: some("pay"),
          mintArgs: {
            tokenPayment: some({
                mint: tokenMint,
                destinationAta: destinationAta,
            }),
          },
          tokenStandard: TokenStandard.ProgrammableNonFungible,
        })
      )
      .sendAndConfirm(umi);
    
      console.log( "Mint Success!!!", pMint )
      enqueueSnackbar(
        "Mint Success!!!",
        {
          variant: "success",
          anchorOrigin: { vertical: "top", horizontal: "right" },
        }
      );
      }
    } catch (error) {
      console.error("Mint Error", error);
      enqueueSnackbar("Mint Error: Check console logs for more details", {
        variant: "error",
        anchorOrigin: { vertical: "top", horizontal: "right" },
      });
    }
    setIsUserMinting(false);
  };

I'm using these node packages

    "@metaplex-foundation/js": "0.19.4",
    "@metaplex-foundation/mpl-candy-machine": "^6.0.0-alpha.12",
    "@metaplex-foundation/umi": "0.8.2",
    "@metaplex-foundation/umi-bundle-defaults": "0.8.3",
    "@metaplex-foundation/umi-signer-wallet-adapters": "0.8.2",
    "@project-serum/anchor": "^0.26.0",
    "@solana/spl-token": "^0.3.7",
    "@solana/wallet-adapter-base": "^0.9.22",
    "@solana/wallet-adapter-react": "^0.15.32",
    "@solana/wallet-adapter-react-ui": "^0.9.31",
    "@solana/wallet-adapter-wallets": "^0.19.16",
    "@solana/web3.js": "^1.74.0",
1
  • I'm going through the same issue using pretty much the same code... Did you manage to solve it by any chance ?
    – Tim88
    Jan 5 at 16:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.