I am trying to mint NFTs from a candy machine v3 using the umi library as shown in this https://docs.metaplex.com/programs/candy-machine/minting . I am using the following code -

import React from 'react'
import { Metaplex, walletAdapterIdentity } from "@metaplex-foundation/js";
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { useMemo, useState } from "react";
import {
 } from "@metaplex-foundation/umi";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import  {mintV2}  from "@metaplex-foundation/mpl-candy-machine";
import { setComputeUnitLimit } from "@metaplex-foundation/mpl-essentials";
import {
  } from "@solana/web3.js";

 const MintNFT = () => {
 const { publicKey, wallet } = useWallet();
 const [nft, setNft] = useState(null);
 const umi = useMemo(
    () => createUmi(process.env.NEXT_PUBLIC_SOLANA_RPC_HOST),
   const connection = useMemo(
   () => new Connection(process.env.NEXT_PUBLIC_SOLANA_RPC_HOST, "confirmed"),
       const candyMachineAddress = new PublicKey(
     const metaplex = useMemo(
  () => Metaplex.make(connection).use(walletAdapterIdentity(wallet)),
   [connection, wallet]
  let candyMachine;
  let walletBalance;
 const onClick = async () => {
// Here the actual mint happens. Depending on the guards that you are using you have to run some pre validation beforehand
// Read more: https://docs.metaplex.com/programs/candy-machine/minting#minting-with-pre-validation
// read candy machine state from chain
candyMachine = await metaplex
  .findByAddress({ address: candyMachineAddress });
await transactionBuilder()
  .add(setComputeUnitLimit(umi, { units: 800_000 }))
    mintV2(umi, {
      candyMachine: candyMachine.address,
      collectionMint: candyMachine.collectionMintAddress,
      collectionUpdateAuthority: candyMachine.authorityAddress,
      mintArgs: {
        mintLimit: some({ id: 1 }),
        solPayment: some({ destination: candyMachine.authorityAddress }),

  return (
  <div>Here we mint the NFT</div>
    className="bg-blue-400 text-sm text-white rounded-full hover:bg-blue-600 m-0 mt-4 py-2 px-8"
    mint NFT
  {nft && (
    <div className={styles.nftPreview}>
        src={nft?.json?.image || "/fallbackImage.jpg"}
        alt="The downloaded illustration of the provided NFT address."

   export default MintNFT

but on clicking the Mint NFT button I am getting the following error -
caught (in promise) ProgramNotRecognizedError: The provided program name [mplCandyGuard] is not recognized in the [devnet] cluster. Did you forget to register this program? If so, you may use "context.programs.add(myProgram)" to fix this.

Source: SDK Can somebody please suggest what is wrong and how to rectify the error?

1 Answer 1


Unfortunately I can not see in your code snippet how you initialise umi, but what you basically need to do to register the guard program is:


In my personal mint ui implementation the umi definition currently looks like this

const umi = createUmi(endpoint) .use(walletAdapterIdentity(wallet)) .use(mplTokenMetadata()) .use(mplCandyMachine())

  • walletAdapterIdentity is needed for the browser wallets to work.
  • mplTokenMetadata To load the nft metadata after the mint.
  • mplCandyMachine to register the candy guard and candy machine programs

Please note, that you should not need @metaplex-foundation/js when using umi. All functions can be replaced with nether new modules. (This can be relevant for size / speed improvements)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.