metaplex-foundation / umi-hotline

2 stars 0 forks source link

error when minting a pNFT from a Sugar-created CMv3 with UMI #3

Closed Maxisy closed 1 year ago

Maxisy commented 1 year ago

Umi version

"@metaplex-foundation/umi": "^0.7.2",

Code

import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import {
  fetchCandyGuard,
  fetchCandyMachine,
  mintV2,
  mplCandyMachine,
} from "@metaplex-foundation/mpl-candy-machine";
import { setComputeUnitLimit } from "@metaplex-foundation/mpl-essentials";
import {
  transactionBuilder,
  publicKey,
  createSignerFromKeypair,
  signerIdentity,
  generateSigner,
} from "@metaplex-foundation/umi";
import base58 from "bs58";

(async () => {
  const umi = createUmi("xxx").use(mplCandyMachine());

  const cmPubkey = publicKey("CyGjuv6ucxWmsNiraWTnhjb4swWR17XLb83Um6DdGn3u");
  const candyMachine = await fetchCandyMachine(umi, cmPubkey);
  const candyGuard = await fetchCandyGuard(umi, candyMachine.mintAuthority);
  const collectionNftPubkey = publicKey(
    "6v8b8pdZcXUuAsLW6bjfVdFo3aCXKXrP2XojJXzeuSa7"
  );
  const updateAuthPubkey = publicKey(
    "483GfHDSQefFrcsStXyFjoNKFpef13TBTPKXBw28Z3V7"
  );

  const mintAuthority = umi.eddsa.createKeypairFromSecretKey(base58.decode("xxx"));
  const mintSigner = createSignerFromKeypair(umi, mintAuthority);
  const nftMint = generateSigner(umi);

  umi.use(signerIdentity(mintSigner));

  const mint = await transactionBuilder()
    .add(setComputeUnitLimit(umi, { units: 800_000 }))
    .add(
      mintV2(umi, {
        candyGuard: candyGuard.publicKey,
        candyMachine: cmPubkey,
        nftMint,
        collectionMint: collectionNftPubkey,
        collectionUpdateAuthority: updateAuthPubkey,
      })
    )
    .sendAndConfirm(umi);

  console.log("Minted, tx: ", mint.signature);
})()

Error

The addressGate guard is the only guard that's set up, and the address that is allowed is `483GfHDSQefFrcsStXyFjoNKFpef13TBTPKXBw28Z3V7`.
The secret key provided to `umi.eddsa.createKeypairFromSecretKey()` in the `mintAuthority` variable is corresponding to that same address as in the addressGate guard, `483GfHDSQefFrcsStXyFjoNKFpef13TBTPKXBw28Z3V7`.

The error that's being thrown in the transaction is: `AddressNotFoundInAllowedList: Address not found on the allowed list`.

This has been tested on devnet, the CMv3 is deployed on devnet too.
lorisleiva commented 1 year ago

Hi there 👋

Oh I remember this happening to me a little while ago.

The AddressNotFoundInAllowedList error is unfortunately wrong because the error code from the program logs comes from a nested instruction which comes from another program. So the framework tries to resolve the error code with the candy machine program and in this case it matches another error.

Could you please provide the entire program log because I don't remember the exact solution but I know that seeing the program logs will make me remember haha.

Maxisy commented 1 year ago

Hey, thanks for the response. This is the complete output of the TS script:

AddressNotFoundInAllowedList: Address not found on the allowed list

Source: Program > mplCandyGuard [Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g]

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

Program Logs:
| Program ComputeBudget111111111111111111111111111111 invoke [1]
| Program ComputeBudget111111111111111111111111111111 success
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g invoke [1]
| Program log: Instruction: MintV2
| Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR invoke [2]
| Program log: Instruction: MintV2
| Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [3]
| Program log: IX: Create
| Program log: Init mint
| Program 11111111111111111111111111111111 invoke [4]
| Program 11111111111111111111111111111111 success
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]
| Program log: Instruction: InitializeMint2
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2828 of 696050 compute units
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
| Program log: Transfer 5616720 lamports to the new account
| Program 11111111111111111111111111111111 invoke [4]
| Program 11111111111111111111111111111111 success
| Program log: Allocate space for the account
| Program 11111111111111111111111111111111 invoke [4]
| Program 11111111111111111111111111111111 success
| Program log: Assign the account to the owning program
| Program 11111111111111111111111111111111 invoke [4]
| Program 11111111111111111111111111111111 success
| Program log: Transfer 2853600 lamports to the new account
| Program 11111111111111111111111111111111 invoke [4]
| Program 11111111111111111111111111111111 success
| Program log: Allocate space for the account
| Program 11111111111111111111111111111111 invoke [4]
| Program 11111111111111111111111111111111 success
| Program log: Assign the account to the owning program
| Program 11111111111111111111111111111111 invoke [4]
| Program 11111111111111111111111111111111 success
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]
| Program log: Instruction: SetAuthority
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3090 of 627730 compute units
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]
| Program log: Instruction: SetAuthority
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3250 of 621570 compute units
| Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
| Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 104310 of 713745 compute units
| Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s success
| Program log: AnchorError occurred. Error Code: MissingTokenRecord. Error Number: 6026. Error Message: Missing token record.
| Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR consumed 144444 of 750502 compute units
| Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR failed: custom program error: 0x178a
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g consumed 193942 of 800000 compute units
| Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: custom program error: 0x178a

    at getMplCandyGuardErrorFromCode (/root/pnft-airdrop/node_modules/@metaplex-foundation/mpl-candy-machine/src/generated/errors/mplCandyGuard.ts:744:24)
    at Object.getErrorFromCode (/root/pnft-airdrop/node_modules/@metaplex-foundation/mpl-candy-machine/src/generated/programs/mplCandyGuard.ts:30:43)
    at Object.resolveError (/root/pnft-airdrop/node_modules/@metaplex-foundation/umi-program-repository/src/createDefaultProgramRepository.ts:122:35)
    at Object.sendTransaction (/root/pnft-airdrop/node_modules/@metaplex-foundation/umi-rpc-web3js/src/createWeb3JsRpc.ts:289:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async TransactionBuilder.sendAndConfirm (/root/pnft-airdrop/node_modules/@metaplex-foundation/umi/src/TransactionBuilder.ts:303:23)
    at async /root/pnft-airdrop/testMint.ts:45:16 {
  source: 'program',
  sourceDetails: 'mplCandyGuard [Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g]',
  cause: SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 1: custom program error: 0x178a
      at Connection.sendEncodedTransaction (/root/pnft-airdrop/node_modules/@solana/web3.js/src/connection.ts:5860:13)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async Connection.sendRawTransaction (/root/pnft-airdrop/node_modules/@solana/web3.js/src/connection.ts:5819:20)
      at async Object.sendTransaction (/root/pnft-airdrop/node_modules/@metaplex-foundation/umi-rpc-web3js/src/createWeb3JsRpc.ts:281:25)
      at async TransactionBuilder.sendAndConfirm (/root/pnft-airdrop/node_modules/@metaplex-foundation/umi/src/TransactionBuilder.ts:303:23)
      at async /root/pnft-airdrop/testMint.ts:45:16 {
    logs: [
      'Program ComputeBudget111111111111111111111111111111 invoke [1]',
      'Program ComputeBudget111111111111111111111111111111 success',
      'Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g invoke [1]',
      'Program log: Instruction: MintV2',
      'Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR invoke [2]',
      'Program log: Instruction: MintV2',
      'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [3]',
      'Program log: IX: Create',
      'Program log: Init mint',
      'Program 11111111111111111111111111111111 invoke [4]',
      'Program 11111111111111111111111111111111 success',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]',
      'Program log: Instruction: InitializeMint2',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2828 of 696050 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program log: Transfer 5616720 lamports to the new account',
      'Program 11111111111111111111111111111111 invoke [4]',
      'Program 11111111111111111111111111111111 success',
      'Program log: Allocate space for the account',
      'Program 11111111111111111111111111111111 invoke [4]',
      'Program 11111111111111111111111111111111 success',
      'Program log: Assign the account to the owning program',
      'Program 11111111111111111111111111111111 invoke [4]',
      'Program 11111111111111111111111111111111 success',
      'Program log: Transfer 2853600 lamports to the new account',
      'Program 11111111111111111111111111111111 invoke [4]',
      'Program 11111111111111111111111111111111 success',
      'Program log: Allocate space for the account',
      'Program 11111111111111111111111111111111 invoke [4]',
      'Program 11111111111111111111111111111111 success',
      'Program log: Assign the account to the owning program',
      'Program 11111111111111111111111111111111 invoke [4]',
      'Program 11111111111111111111111111111111 success',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]',
      'Program log: Instruction: SetAuthority',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3090 of 627730 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]',
      'Program log: Instruction: SetAuthority',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3250 of 621570 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 104310 of 713745 compute units',
      'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s success',
      'Program log: AnchorError occurred. Error Code: MissingTokenRecord. Error Number: 6026. Error Message: Missing token record.',
      'Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR consumed 144444 of 750502 compute units',
      'Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR failed: custom program error: 0x178a',
      'Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g consumed 193942 of 800000 compute units',
      'Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: custom program error: 0x178a'
    ]
  },
  program: {
    name: 'mplCandyGuard',
    publicKey: { bytes: [Uint8Array] },
    getErrorFromCode: [Function: getErrorFromCode],
    getErrorFromName: [Function: getErrorFromName],
    isOnCluster: [Function: isOnCluster],
    availableGuards: [
      'botTax',           'solPayment',
      'tokenPayment',     'startDate',
      'thirdPartySigner', 'tokenGate',
      'gatekeeper',       'endDate',
      'allowList',        'mintLimit',
      'nftPayment',       'redeemedAmount',
      'addressGate',      'nftGate',
      'nftBurn',          'tokenBurn',
      'freezeSolPayment', 'freezeTokenPayment',
      'programGate'
    ]
  },
  logs: [
    'Program ComputeBudget111111111111111111111111111111 invoke [1]',
    'Program ComputeBudget111111111111111111111111111111 success',
    'Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g invoke [1]',
    'Program log: Instruction: MintV2',
    'Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR invoke [2]',
    'Program log: Instruction: MintV2',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [3]',
    'Program log: IX: Create',
    'Program log: Init mint',
    'Program 11111111111111111111111111111111 invoke [4]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]',
    'Program log: Instruction: InitializeMint2',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2828 of 696050 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program log: Transfer 5616720 lamports to the new account',
    'Program 11111111111111111111111111111111 invoke [4]',
    'Program 11111111111111111111111111111111 success',
    'Program log: Allocate space for the account',
    'Program 11111111111111111111111111111111 invoke [4]',
    'Program 11111111111111111111111111111111 success',
    'Program log: Assign the account to the owning program',
    'Program 11111111111111111111111111111111 invoke [4]',
    'Program 11111111111111111111111111111111 success',
    'Program log: Transfer 2853600 lamports to the new account',
    'Program 11111111111111111111111111111111 invoke [4]',
    'Program 11111111111111111111111111111111 success',
    'Program log: Allocate space for the account',
    'Program 11111111111111111111111111111111 invoke [4]',
    'Program 11111111111111111111111111111111 success',
    'Program log: Assign the account to the owning program',
    'Program 11111111111111111111111111111111 invoke [4]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]',
    'Program log: Instruction: SetAuthority',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3090 of 627730 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [4]',
    'Program log: Instruction: SetAuthority',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3250 of 621570 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 104310 of 713745 compute units',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s success',
    'Program log: AnchorError occurred. Error Code: MissingTokenRecord. Error Number: 6026. Error Message: Missing token record.',
    'Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR consumed 144444 of 750502 compute units',
    'Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR failed: custom program error: 0x178a',
    'Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g consumed 193942 of 800000 compute units',
    'Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: custom program error: 0x178a'
  ],
  code: 6026
}

This seems to be causing the problem: Program log: AnchorError occurred. Error Code: MissingTokenRecord. Error Number: 6026. Error Message: Missing token record

lorisleiva commented 1 year ago

Ah yes! The TokenRecord will only be passed if the JS Client knows you're trying to mint a PNFT. You must pass the tokenStandard argument for that purpose.

const mint = await transactionBuilder()
  .add(setComputeUnitLimit(umi, { units: 800_000 }))
  .add(
    mintV2(umi, {
      candyGuard: candyGuard.publicKey,
      candyMachine: cmPubkey,
      nftMint,
      collectionMint: collectionNftPubkey,
      collectionUpdateAuthority: updateAuthPubkey,
      tokenStandard: TokenStandard.ProgrammableNonFungible, // <-- Add this line.
    })
  )
  .sendAndConfirm(umi);
Maxisy commented 1 year ago

Thanks, it's working perfectly that way