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?