0

我在 devnet 上部署了一个程序,当我运行锚测试时,一切运行良好。该程序需要 3 个键,然后返回 ok() (我评论了里面的所有内容)。

我试图在我的单页应用程序(带有幻像签名)中调用该程序,但出现以下错误:自定义程序错误:0x64

我认为问题很简单,但我不明白原因。

const instructions: TransactionInstruction[] = [];  

const exchangeInstruction = new TransactionInstruction({

    programId: program_id,
    data: Buffer.alloc(0),
    keys: [

        { pubkey: publicKey1, isSigner: true, isWritable: true },

        { pubkey: publicKey2, isSigner: false, isWritable: true },

        { pubkey: system_program, isSigner: false, isWritable: false },

    ],
});

instructions.push(exchangeInstruction);

const transaction = new Transaction().add(...instructions);

transaction.feePayer = publicKey1;
transaction.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;

var signedTransaction = await window.solana.signTransaction(transaction);

var signature = await connection.sendRawTransaction(signedTransaction.serialize());

公钥来自 new PublicKey(...)

program_id 是我的程序的公钥(PublicKey())

我的程序中没有参数(我试图删除数据:{...} 但得到了同样的错误)。

当我使用 .ts 文件和锚点测试调用程序时,一切正常,代码如下:

const tx = await program.rpc.initialize(
{
  accounts: {
    publicKey1: xxxx.publicKey,
    publicKey2: yyyy.publicKey,
    
    systemProgram: anchor.web3.SystemProgram.programId,
  },

  signers: [xxxx]
});

我一定在某个地方遗漏了一些东西,但不知道在哪里,如果有人可以提供帮助,将不胜感激

4

1 回答 1

0

根据 Anchor 文档,error code0x64对应十进制的 100 是InstructionMissing,必须为您的指令编号提供一些 8 字节的标识符。

要解决这个问题,您可能需要将指令数据声明为:

data: Buffer.alloc(8),

参考https://docs.rs/anchor-lang/latest/src/anchor_lang/error.rs.html#19

于 2022-01-29T11:33:53.927 回答