[英]Customized candy machine: ProgramError: 102: The program could not deserialize the given instruction
我已經分叉了metaplex 代碼,並且正在嘗試實現具有預售功能的糖果機。 您可以查看此拉取請求以供參考: https://github.com/FluffyPorcupine/metaplex/pull/1/files 。 我修改了 rust lib.rs 和 candy-machine-cli.ts 文件來實現我認為它可能的工作方式。
我能夠成功地將程序部署到 solana 和錨點,將 idl 部署到錨點(按照這些步驟),並使用 cli 將文件上傳到 assets 文件夾中。 我的下一步是嘗試並實際創建一個糖果機。 這是我要運行的命令:
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
當我運行命令時,我得到以下堆棧跟蹤:
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'
}
我對調試 rust/anchor 非常陌生。 我的代碼中有什么東西對某人來說很明顯,為什么我會根據我在 PR 中對相關文件的更改而收到此錯誤? 或者關於我可以調試它的方法的任何提示? 我也嘗試過運行“錨點測試”,但得到了同樣的錯誤。
不確定 metaplex,但是當我在使用錨和 solana/web3 時遇到同樣的錯誤幾次時,這是因為idl
文件和前端 rpc 代碼之間的鍵不匹配鍵。 例如:idl 文件看起來像這樣
.....
"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
在前端,我試圖訪問該程序
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
我在前端 rpc 中使用mainAccount
而不是baseAccount
,這是 idl 文件中的關鍵。 它必須是
await program.rpc.initialize({
accounts: {
baseAccount: baseAccount.publicKey,
authority: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [baseAccount],
});
您能否檢查包含需要在 RPC 調用上傳遞的值的變量。
當我錯誤地將變量初始化為時,我得到了同樣的錯誤
myVariable : "Hello";
代替,
myVariable = "Hello";
如果您嘗試使用處理程序與指令宏使用不同類型的參數,您將收到此錯誤。 IE。 你在處理程序參數中使用了u8
然后你在 #[ usize
#[instruction()]
宏中使用了:
pub fn some_ix(ctx: Context<SomeIx>, index: u8) -> Result<()> {
// ...
}
// then
#[derive(Accounts)]
#[instruction(index: usize)] // <- this is what causing the issue
pub struct SomeIx {
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.