Metaplex Candy Machine v3 NFT Creation Fails with BorshIoError 'Unknown variant index: 1'

Issue Overview

I’m getting a serialization error when trying to create NFTs with my Candy Machine v3 setup. The minting process fails with a BorshIoError that shows ‘Unknown variant index: 1’ in the transaction logs.

Error Details

Transaction failed: SendTransactionError occurred during simulation.
Error: Failed to process Instruction 2 - serialization issue with account data.
Program Logs:
[
  "Program log: Instruction: MintV2",
  "Program 11111111111111111111111111111111 invoke [2]",
  "Program 11111111111111111111111111111111 success",
  "Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR invoke [2]",
  "Program log: Instruction: MintV2",
  "Program log: Error occurred - BorshIoError with message: Unknown variant index: 1. Error Code: 64424509440",
  "Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR used 35507 compute units of 748405",
  "Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR failed: serialization error",
  "Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g used 86802 compute units of 799700",
  "Program Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g failed: account data error"
]

Setup Code

Machine Creation

const client = createUmi(
  PROJECT_CONFIG.SOLANA_RPC || 'https://api.devnet.solana.com'
)
  .use(mplCandyMachine())
  .use(mplTokenMetadata());

const WALLET_FILE = path.join(__dirname, 'creator-wallet.json');
const walletData = new Uint8Array(
  JSON.parse(fs.readFileSync(WALLET_FILE, 'utf-8'))
);
const creatorKeypair = client.eddsa.createKeypairFromSecretKey(walletData);
const walletSigner = createSignerFromKeypair(client, creatorKeypair);
client.use(keypairIdentity(walletSigner));

console.log('Creator wallet:', walletSigner.publicKey.toString());

const seriesMint = generateSigner(client);
const seriesAuthority = walletSigner;

await createNft(client, {
  mint: seriesMint,
  authority: client.identity,
  name: "test-collection-name",
  uri: "collection-metadata-url",
  sellerFeeBasisPoints: percentAmount(3, 2),
  isCollection: true,
}).sendAndConfirm(client);

const machineKeypair = generateSigner(client);

const createTx = await create(client, {
  candyMachine: machineKeypair,
  collectionMint: seriesMint.publicKey,
  collectionUpdateAuthority: client.identity,
  tokenStandard: TokenStandard.NonFungible,
  sellerFeeBasisPoints: percentAmount(3, 2),
  itemsAvailable: BigInt(1000),
  creators: [
    {
      address: publicKey(PAYMENT_WALLET),
      verified: true,
      percentageShare: 100
    }
  ],
  configLineSettings: some({
    prefixName: "",
    nameLength: 32,
    prefixUri: "",
    uriLength: 200,
    isSequential: true
  }),
  guards: {
    startDate: some({ 
      date: dateTime("2025-01-15T00:00:00.000Z")
    }),
    endDate: some({ 
      date: dateTime("2025-03-15T00:00:00.000Z")
    }),
    solPayment: some({
      lamports: sol(0.5),
      destination: publicKey(PAYMENT_WALLET),
    })
  }
});

Minting Service

async createToken(machineAddress: string) {
  try {
    const machine = await fetchCandyMachine(
      this.client,
      publicKey(machineAddress)
    );

    const tokenMint = generateSigner(this.client);
    
    const transaction = await transactionBuilder()
      .add(setComputeUnitLimit(this.client, { units: 900_000 }))
      .add(
        mintV2(this.client, {
          candyMachine: machine.publicKey,
          nftMint: tokenMint,
          collectionMint: machine.collectionMint,
          collectionUpdateAuthority: machine.authority,
          mintArgs: {
            solPayment: some({
              destination: publicKey(PAYMENT_WALLET)
            }),
          }
        })
      );

    return await transaction.sendAndConfirm(this.client);
  } catch (err) {
    console.error('Token creation failed:', err);
    throw err;
  }
}

Package Versions

{
  "dependencies": {
    "@metaplex-foundation/mpl-candy-machine": "^6.1.0",
    "@metaplex-foundation/mpl-token-metadata": "^3.4.0",
    "@metaplex-foundation/umi": "^1.0.0",
    "@metaplex-foundation/umi-bundle-defaults": "^1.0.0"
  }
}

Testing Environment

  • Solana Devnet
  • Candy Machine v3
  • Current UMI versions

What I Need Help With

This serialization error is blocking my NFT creation process. I’ve verified that all metadata was uploaded correctly and the machine deployment worked fine. The error seems to happen during the actual minting step. Has anyone encountered this specific BorshIoError before? What could cause this variant index issue during NFT minting?

looks like your candy machine program and sdk versions dont match. i got the same borsh errors when my @metaplex-foundation/mpl-candy-machine was behind the on-chain program. update to the latest version or downgrade if you’re using cutting edge. that 900k compute limit might be too high too - try 800k.

The Problem:

You’re encountering a BorshIoError: Unknown variant index: 1 when minting NFTs using Candy Machine v3. This serialization error indicates a mismatch between your Candy Machine’s guard configuration and the arguments provided during the minting process. The transaction logs show the error originates within the mintV2 instruction.

:thinking: Understanding the “Why” (The Root Cause):

The BorshIoError: Unknown variant index: 1 arises because the Candy Machine program on the Solana blockchain expects specific data (in this case, guard data) during the minting transaction. If the program’s configuration (guards defined during Candy Machine creation) includes certain guards (like startDate, endDate, solPayment), the minting instruction (mintV2) must also include corresponding arguments for those guards, even if those guards’ conditions are already met. The “unknown variant index” signifies that the program received an unexpected data structure because the arguments didn’t match the expected guard configuration.

:gear: Step-by-Step Guide:

  1. Adjust the mintArgs in your createToken function: Ensure that your mintArgs object includes arguments for all active guards defined during Candy Machine creation. Your current mintArgs only includes solPayment. Since your create function includes startDate and endDate guards, you must also include them in mintArgs, even if they are already satisfied:
async createToken(machineAddress: string) {
  try {
    // ... (rest of your code)

    const transaction = await transactionBuilder()
      .add(setComputeUnitLimit(this.client, { units: 900_000 }))
      .add(
        mintV2(this.client, {
          candyMachine: machine.publicKey,
          nftMint: tokenMint,
          collectionMint: machine.collectionMint,
          collectionUpdateAuthority: machine.authority,
          mintArgs: {
            solPayment: some({
              destination: publicKey(PAYMENT_WALLET)
            }),
            startDate: some({}), // Add this line
            endDate: some({})    // Add this line
          }
        })
      );

    // ... (rest of your code)
  } catch (err) {
    // ... (rest of your code)
  }
}
  1. Verify your create function’s guard configuration: Double-check that the guards object in your create function accurately reflects your desired guard conditions. Ensure the guard data types match the expected input for each guard. Incorrect data types can also lead to serialization errors.

  2. Test with reduced compute units: While unlikely to be the root cause given the specific error, the provided 900,000 compute units might be excessively high. Try reducing this to 800,000 or even lower as suggested in other answers.

:mag: Common Pitfalls & What to Check Next:

  • Incorrect Guard Data Types: Ensure the data types used for the startDate, endDate, and solPayment within mintArgs match exactly the data types expected by your Candy Machine guards. Pay close attention to the use of some({}) to handle optional guards correctly.
  • Outdated Packages: Although less likely the main issue here, make sure your @metaplex-foundation/mpl-candy-machine package is up-to-date to avoid version mismatches with the on-chain program.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

Hmm, interesting error! I’ve seen borsh serialization issues before, but not this exact variant.

Quick question - is your collection NFT actually verified? I see you’re creating the collection in your setup code, but where’s the verifyCollectionV1 call?

Try minting without guards first to isolate the problem. Comment out the entire guards section and see if basic minting works. That variant index error might be coming from your collection metadata structure.

Also, double-check your metadata JSON files. Do they follow candy machine’s exact schema? Sometimes tiny differences in attribute formatting cause these weird serialization errors.

One more thing - are you loading config lines after creation? Your code has configLineSettings but no addConfigLines call. The machine needs those populated before minting works.

What’s your actual metadata JSON look like? Any other console errors before this borsh error shows up?