1

I'm having trouble minting an NFT using @metaplex-foundation/[email protected]. Whenever I try to do so, I get the following error: AnchorError caused by account: candy_guard. Error Code: AccountOwnedByWrongProgram.

Here's the code I'm using:

const mint = async () => {
  if (!wallet?.connected || !candyMachine) {
    return;
  }

  const umi = createUmi(SOLANA_RPC_ENDPOINT)
    .use(walletAdapterIdentity(wallet))
    .use(mplCandyMachine());

  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,
        candyGuard: candyMachine.mintAuthority,
        mintArgs: {
          mintLimit: some({ id: 1 })
        }
      })
    )
    .sendAndConfirm(umi);
};

This is the error message that I'm receiving:

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: 0xbbf

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: AccountOwnedByWrongProgram. Error Number: 3007. Error Message: The given account is owned by a different program than expected.
| Program log: Left:
| Program log: 11111111111111111111111111111111
| Program log: Right:
| Program log: Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g consumed 10260 of 1000000 compute units
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: custom program error: 0xbbf

    at Object.resolveError (createDefaultProgramRepository.mjs:84:1)
    at Object.sendTransaction (createWeb3JsRpc.mjs:158:1)
    at async TransactionBuilder.sendAndConfirm (TransactionBuilder.mjs:209:1)
    at async mint (cmProvider.tsx:84:19)
    at async handleMint (index.tsx:24:17)

Here are the dependencies:

"@metaplex-foundation/mpl-candy-machine": "^6.0.0",
"@metaplex-foundation/umi": "^0.8.10",
"@metaplex-foundation/umi-bundle-defaults": "^0.8.10",
"@metaplex-foundation/umi-signer-wallet-adapters": "^0.8.10",
"@solana/spl-token": "^0.3.8",
"@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.76.0"

The Candy machine ID is Ao9bam2dURrcbapnRg6kseAeAeaiCMnJGHncdnRCTSQ.

1 Answer 1

1

Problem

This issue is caused by the candyGuard account. According to the error logs, its program owner is invalid — i.e. it is not owned by the Candy Guard program you are sending the transaction to. More often than not, this will occur when the provided candyGuard account does not exist as its assigned program will be automatically set to the System program.

Since the candyGuard account is not explicitly provided in your code snippet, it will default to deriving its address using the provided candyMachine account as the base seed of its PDA.

If you created your candyGuard account using a different convention — e.g. by using another library or website — than the default value may be wrong.

Solution

Providing the correct candyGuard account explicitly to the mintV2 instruction should fix your issue.

Since it seems you are already fetching and decoding the data of your candy machine account, you may use the mintAuthority data attribute since it will always be equal to the address of the associated candy guard account when one is set.

mintV2(umi, {
  candyMachine: candyMachine.publicKey,
  candyGuard: candyMachine.mintAuthority,
  // ...
});

Disclaimer

This problem/solution statement assumes you are indeed guarding your candy machine using the Candy Guard program — which is the case 99% of the time. If you want to mint from a candy machine directly as its mint authority, you will need to use the mintFromCandyMachineV2 instruction.

You can read more about the minting process in the official Metaplex documentation.

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.