1

I have used the Sugar CLI to upload a test candy machine with just 2 items and the collection data, and then set up a simple mintLimit guard.

Am am able to find the candyMachine and see all of the info for both it and the candyGuard using umi. However when I try to mint from it, I get an error.

This is my front end code:

    import { useWallet } from '@solana/wallet-adapter-react';
    import { FC } from 'react';
    import { notify } from 'utils/notifications';
    import { mintV2, mplCandyMachine, fetchCandyMachine } from "@metaplex-foundation/mpl-candy-machine";
    import { setComputeUnitLimit } from "@metaplex-foundation/mpl-toolbox";
    import { transactionBuilder, generateSigner, publicKey, some } from "@metaplex-foundation/umi";
    import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
    import { walletAdapterIdentity } from '@metaplex-foundation/umi-signer-wallet-adapters';
    
    export const Nfts: FC = () => {
        
        const wallet = useWallet();
        const mintNFT = async () => {
    
            notify({ message: 'Minting NFT', description: 'Please wait...' });
    
            const umi = createUmi("https://api.devnet.solana.com")
                .use(walletAdapterIdentity(wallet))
                .use(mplCandyMachine());
    
            const candyMachinePublicKey = publicKey("xxx---MyCandyMachineKeyHere---xxx");
            const candyMachine = await fetchCandyMachine(umi, candyMachinePublicKey);
            const nftMint = generateSigner(umi);
    
            await transactionBuilder()
                .add(setComputeUnitLimit(umi, { units: 1_000_000 }))
                .add(
                    mintV2(umi, {
                        candyMachine: candyMachine.publicKey,
                        nftMint,
                        collectionMint: candyMachine.collectionMint,
                        collectionUpdateAuthority: candyMachine.authority,
                        mintArgs: {
                            mintLimit: some({ id: 1 }),
                        },
                    })
                )
                .sendAndConfirm(umi);
        };
    
        return (
            <div>
                <div className="relative group items-center">
                    <div className="m-1 absolute -inset-0.5 bg-gradient-to-r from-indigo-500 to-fuchsia-500 
                                                    rounded-lg blur opacity-20 group-hover:opacity-100 transition duration-1000 group-hover:duration-200 animate-tilt"></div>
                    <button
                        className="px-8 m-2 btn animate-pulse bg-gradient-to-br from-indigo-500 to-fuchsia-500 hover:from-white hover:to-purple-300 text-black"
                        onClick={() => mintNFT()}
                    >
                        <span>Dummy Mint</span>
                    </button>
    
                </div>
            </div>
        );
    };

The error I get is from the candy_guard program.

Uncaught (in promise) ProgramErrorNotRecognizedError: The program [mplCandyGuard] at address [Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g] raised an error that is not recognized by the programs registered on the SDK. Please check the underlying program error below for more details.

Source: Program > mplCandyGuard [Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g]

Caused By: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 1: custom program error: 0xbc4

Program Logs:
| Program ComputeBudget111111111111111111111111111111 invoke [1]
| Program ComputeBudget111111111111111111111111111111 success
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g invoke [1]
| Program log: Instruction: MintV2
| Program log: AnchorError caused by account: candy_guard. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized.
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g consumed 9739 of 1000000 compute units
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: custom program error: 0xbc4

    at Object.y [as resolveError] (229-6a6ac4f97ae95025.js:12:1770)
    at Object.b [as sendTransaction] (229-6a6ac4f97ae95025.js:12:6206)
    at async o.sendAndConfirm (229-6a6ac4f97ae95025.js:12:34106)

Does anyone know if I'm giving the correct information to the MintV2 instruction there, or if there's anything else I need to attend to before attempting the mint? I've no idea which account it's referring to that it expected to be intialiased. Maybe it's something I can pre-init.

Or is there a preferred method for using v3 machines with a front end?

1 Answer 1

1

The solution was an extra parameter which is not mentioned in the documentation.

            .add(
                mintV2(umi, {
                    candyMachine: candyMachine.publicKey,
                    nftMint,
                    collectionMint: candyMachine.collectionMint,
                    collectionUpdateAuthority: candyMachine.authority,
                    candyGuard: candyMachine.mintAuthority, // This extra param
                    mintArgs: {
                        mintLimit: some({ id: 1 }),
                    },
                })
            )

The candgyGuard option take the mintAuthority as it's value, and this succesfully minted.

Your Answer

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

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