Metaplex Candy Machine v3 NFT Creation Error: BorshIoError with variant index 1

Issue Summary

I’m encountering a BorshIoError while attempting to mint NFTs using Candy Machine v3. The error message states, “Unexpected variant index: 1,” which appears during the simulation of the transaction.

Error Details

Transaction simulation failed: Error processing Instruction 2: Failed to serialize or deserialize account data
Program log: ProgramError occurred. Error Code: BorshIoError("Unexpected variant index: 1")
Program CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR failed

Setup Code

// Set up the UMI framework
const umiClient = createUmi(
  BLOCKCHAIN_CONFIG.ENDPOINT || 'https://api.devnet.solana.com'
)
  .use(mplCandyMachine())
  .use(mplTokenMetadata());

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

// Create collection NFT first
const collectionKeypair = generateSigner(umiClient);

await createNft(umiClient, {
  mint: collectionKeypair,
  authority: umiClient.identity,
  name: "Test Collection",
  uri: "https://example.com/collection.json",
  sellerFeeBasisPoints: percentAmount(2.5, 2),
  isCollection: true,
}).sendAndConfirm(umiClient);

// Prepare candy machine
const machineKeypair = generateSigner(umiClient);

const createTx = await create(umiClient, {
  candyMachine: machineKeypair,
  collectionMint: collectionKeypair.publicKey,
  collectionUpdateAuthority: umiClient.identity,
  tokenStandard: TokenStandard.NonFungible,
  sellerFeeBasisPoints: percentAmount(2.5, 2),
  itemsAvailable: BigInt(100),
  creators: [
    {
      address: publicKey(WALLET_ADDRESS),
      verified: true,
      percentageShare: 100
    }
  ],
  guards: {
    solPayment: some({
      lamports: sol(0.5),
      destination: publicKey(WALLET_ADDRESS),
    })
  }
});

Minting Function

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

    const tokenMint = generateSigner(this.umiClient);
    
    const mintTx = await transactionBuilder()
      .add(setComputeUnitLimit(this.umiClient, { units: 600_000 }))
      .add(
        mintV2(this.umiClient, {
          candyMachine: machine.publicKey,
          nftMint: tokenMint,
          collectionMint: machine.collectionMint,
          collectionUpdateAuthority: machine.authority,
          mintArgs: {
            solPayment: some({
              destination: publicKey(WALLET_ADDRESS)
            }),
          }
        })
      );

    return await mintTx.sendAndConfirm(this.umiClient);
  } catch (err) {
    console.error('NFT creation failed:', err);
    throw err;
  }
}

What I’ve Checked

  • I’m using the latest Metaplex packages
  • Confirmed that the candy machine deployment is successful
  • All addresses are verified as correct
  • Items have been uploaded without issues
  • Sufficient compute units have been allocated

Question: What could be causing this BorshIoError during NFT minting, and how can I resolve the serialization issue?

Your mintArgs structure is the problem. You’re only passing the destination field for solPayment, but the guard needs both lamports and destination. Your candy machine has lamports: sol(0.5) in the guard config, but you’re leaving it out when minting.

Try this:

mintArgs: {
  solPayment: some({
    lamports: sol(0.5),
    destination: publicKey(WALLET_ADDRESS)
  }),
}

The borsh deserializer crashes because it gets a partial structure that doesn’t match what it expects. I hit this same issue when I forgot guard parameters - simulation works fine but serialization bombs out.

Also check that your collection mint is initialized before you try minting. I’ve seen timing issues between collection creation and candy machine setup cause weird state problems.

had this same borsh error last week - my candy machine config got corrupted. try recreating it from scratch with a fresh keypair. also, you’re not awaiting the create transaction before minting, which could cause timing issues with the account state.

Yeah, that borsh serialization error is a pain - I’ve hit similar issues with candy machine v3 before.

First thing I’d check: is your collection NFT actually set up as a verified collection? That “variant index: 1” error often means there’s something wrong with how the collection data is structured.

Also, double-check your wallet setup. You’re loading the creator wallet from JSON - is that the exact same wallet used as the collection update authority? I’ve seen tiny authority mismatches break serialization.

What version of mpl-candy-machine are you running? Recent versions had breaking changes that’ll cause this if you’re mixing old/new code.

Try testing with a completely fresh keypair too - accounts sometimes get into weird states that mess up serialization.

What’s your collection.json metadata look like? Is it following proper Metaplex format?