I have created a CandyMachineV3 using sugar
with the metaplex docs as a reference. And now, I have implemented the NFT mint button in the front end, but I get an error.
[Error Details]
Unable to simulate. Make sure you trust this website since appriving can lead to loss of funds.
ogramErrorNotRecognizedError: 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 9474 of 600000 compute units
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: custom program error: 0xbc4
at DefaultProgramRepository.resolveError (DefaultProgramRepository.mjs:77:1)
at Web3JsRpc.sendTransaction (Web3JsRpc.mjs:159:1)
at async TransactionBuilder.sendAndConfirm (TransactionBuilder.mjs:174:1)
at async mintToken (index.tsx:112:7)
c
[My code: Create CandyMachine and mint]
const getCandyMachineState = async () => {
try {
// Use the RPC endpoint of your choice.
if (
process.env.NEXT_PUBLIC_SOLANA_RPC_HOST &&
process.env.NEXT_PUBLIC_CANDY_MACHINE_ID
) {
const umi = createUmi(process.env.NEXT_PUBLIC_SOLANA_RPC_HOST)
.use(walletAdapterIdentity(walletAddress))
.use(nftStorageUploader())
.use(mplTokenMetadata())
.use(mplCandyMachine());
const candyMachine = await fetchCandyMachine(
umi,
publicKey(process.env.NEXT_PUBLIC_CANDY_MACHINE_ID),
);
const candyGuard = await safeFetchCandyGuard(
umi,
candyMachine.mintAuthority,
);
setUmi(umi);
setCandyMachine(candyMachine);
setCandyGuard(candyGuard);
}
} catch (error) {
console.error(error);
}
};
const mintToken = async () => {
try {
if (umi === undefined) {
throw new Error('Umi context was not initialized.');
}
if (candyMachine === undefined) {
throw new Error('Candy Machine was not initialized.');
}
const nftSigner = generateSigner(umi);
await transactionBuilder()
.add(setComputeUnitLimit(umi, { units: 600_000 }))
.add(
mintV2(umi, {
candyMachine: candyMachine.publicKey,
candyGuard: undefined,
nftMint: nftSigner,
collectionMint: candyMachine.collectionMint,
collectionUpdateAuthority: candyMachine.authority,
}),
)
.sendAndConfirm(umi);
} catch (error) {
console.error(error);
}
};
[Environment]
start date
: :.. start date:
: : :.. date: Sun January 1 2023 00:00:00 UTC
I ran $ sugar mint
on the terminal before setting the guard and it succeeded. Is the guard setting on the front end side incorrect.... If anyone knows the cause or solution, please let me know, thank you.
I checked this error again and found that the publicKey for candyGuard was not set correctly.
mintV2(umi, {
candyMachine: candyMachine.publicKey,
candyGuard: candyGuard?.publicKey, // It was not set up correctly.
nftMint: nftSigner,
collectionMint: candyMachine.collectionMint,
collectionUpdateAuthority: candyMachine.authority,
}),
I fixed it and it minted successfully.