metaplex-foundation / umi-hotline

2 stars 0 forks source link

Account not initialized error when minting #14

Closed eli6 closed 1 year ago

eli6 commented 1 year ago

Umi version

0.8.2

Code

const nftMint = generateSigner(umi);
    await transactionBuilder()
      .add(setComputeUnitLimit(umi, { units: 800_000 }))
      .add(
        mintV2(umi, {
          candyMachine: candyMachine.publicKey,
          nftMint,
          collectionMint: candyMachine.collectionMint,
          collectionUpdateAuthority: candyMachine.authority,
          mintArgs: {
            mintLimit: some({ id: 1 }),
            solPayment: some({ destination }),
          },
        })
      )
      .sendAndConfirm(umi);

Error

Candy Machine + guards have been created with sugar-cli 2.2.0

The Phantom wallet shows "Transaction(s) reverted during simulation" and when clicking approve, the following error appears:

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 9836 of 800000 compute units
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: custom program error: 0xbc4

Call Stack
Object.resolveError
node_modules/@metaplex-foundation/umi-program-repository/dist/esm/createDefaultProgramRepository.mjs (84:0)
Object.sendTransaction
node_modules/@metaplex-foundation/umi-rpc-web3js/dist/esm/createWeb3JsRpc.mjs (152:0)
async TransactionBuilder.sendAndConfirm
node_modules/@metaplex-foundation/umi/dist/esm/TransactionBuilder.mjs (191:0)
lorisleiva commented 1 year ago

Hi there,

Are you sure that the candy guard account has been created? If so, it may be that it wasn't derived from the address of the candy machine and therefore you need to pass its address explicitly like so:

const nftMint = generateSigner(umi);
await transactionBuilder()
  .add(setComputeUnitLimit(umi, { units: 800_000 }))
  .add(
    mintV2(umi, {
      candyMachine: candyMachine.publicKey,
      candyGuard: candyMachine.mintAuthority, // <- If a candy machine is associated with a candy guard,
                                              //    it will always be saved as its mint authority.
      nftMint,
      collectionMint: candyMachine.collectionMint,
      collectionUpdateAuthority: candyMachine.authority,
      mintArgs: {
        mintLimit: some({ id: 1 }),
        solPayment: some({ destination }),
      },
    })
  )
  .sendAndConfirm(umi);
eli6 commented 1 year ago

That did the trick, thank you! 😄 I needed to pass the candy guard address explicitly for it to work