我在 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]
});
我一定在某个地方遗漏了一些东西,但不知道在哪里,如果有人可以提供帮助,将不胜感激