'Customized candy machine: ProgramError: 102: The program could not deserialize the given instruction
I've forked the metaplex code, and am trying to implement a candy machine with presale capabilities. You can see this pull request for reference: https://github.com/FluffyPorcupine/metaplex/pull/1/files. I've modified both the rust lib.rs and candy-machine-cli.ts files to implement how I think it might work.
I was able to successfully deploy the program to solana and anchor, deployed the idl to anchor (following these steps), and uploaded the files in the assets folder using the cli. My next step is to try and actually create a candy machine. This is the command I'm trying to run:
ts-node js/packages/cli/src/candy-machine-cli.ts create_candy_machine --env devnet --keypair .config/solana/devnet.json --presale-enabled true --presale-items-available 5
When I run the command, I get the following stack trace:
ProgramError: 102: The program could not deserialize the given instruction
at Function.parse (/home/my-user/dev/Solana/metaplex/js/packages/cli/node_modules/@project-serum/anchor/src/error.ts:41:14)
at Object.rpc [as initializeCandyMachine] (/home/my-user/dev/Solana/metaplex/js/packages/cli/node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:23:42)
at processTicksAndRejections (node:internal/process/task_queues:96:5) { code: 102,
msg: 'The program could not deserialize the given instruction'
}
I'm very new to debugging rust/anchor. Is there something in my code obvious to someone as to why I would be getting this error based on my changes in the PR to the relavant files? Or any tips on ways that I could debug this? I've tried running "anchor test" as well, but just get the same error.
Solution 1:[1]
Can you check the variables that contains the values that needs to be passed on the RPC call.
I got the same error when I have mistakenly initialised the variable as
myVariable : "Hello";
Instead of,
myVariable = "Hello";
Solution 2:[2]
Not sure about metaplex, but when I faced this same error a few times while using anchor and solana/web3, it was because of key mismatch key between idl file and the frontend rpc code.
For eg:
the idl file looked something like this
.....
"instructions": [
{
"name": "initialize",
"accounts": [
{
"name": "baseAccount",
"isMut": true,
"isSigner": true
},
{
"name": "authority",
"isMut": true,
"isSigner": true
},
{
"name": "systemProgram",
"isMut": false,
"isSigner": false
}
],
"args": []
},
{
..... and so on
And in the frontend, where I tried to access the program
const provider = await getProvider(wallet);
const { SystemProgram, Keypair } = web3;
/* create an account */
const baseAccount = Keypair.generate();
const programID = new PublicKey(
".... The Public key here ....."
);
const program = new Program(idl, programID, provider);
try {
/* interact with the program via rpc */
await program.rpc.initialize({
accounts: {
mainAccount: baseAccount.publicKey,
authority: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [baseAccount],
});
....and so on
I used mainAccount in frontend rpc instead of baseAccount, which was the key in the idl file. It had to be
await program.rpc.initialize({
accounts: {
baseAccount: baseAccount.publicKey,
authority: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [baseAccount],
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RuFerdZ |
| Solution 2 |
