I updated from anchor 0.17 to version 0.24, and since then, fetching a collection account fails with an anchor error like:
Error: Invalid account discriminator
This is my code
export const getCollectionPDA = async (candyMachineAddress: string): Promise<anchor.web3.PublicKey> => {
return (
await anchor.web3.PublicKey.findProgramAddress(
[Buffer.from("collection"), new PublicKey(candyMachineAddress).toBuffer()],
new PublicKey(CANDY_MACHINE_PROGRAM_V2)
)
)[0];
};
const provider = new AnchorProvider(connection, getmywallet(), {
preflightCommitment: "finalized",
commitment: "finalized",
});
const idl = await Program.fetchIdl(CANDY_MACHINE_PROGRAM_V2, provider);
const anchorProgram = new Program(idl, CANDY_MACHINE_PROGRAM_V2, provider);
const candyMachineId = "63gzhYWxJ4Yfc5QahLxV6NChSjJZNWW93Sy9CHz8YkCe";
const collectionPDA = await getCollectionPDA(candyMachineId);
const collectionPDAAccount = await connection.getAccountInfo(collectionPDA);
const collectionData = await anchorProgram.account.collectionPda.fetch(new PublicKey(collectionPDA.toString()));
I wonder what's going on here. Perhaps the Collection account struct has been updated and the blockchain contains old structs? And only recently anchor started checking for that?