调试“交易模拟失败”发送程序指令(Solana Solidity)时

发布于 2025-01-18 15:53:20 字数 2106 浏览 1 评论 0原文

当尝试调用使用 @solana/solidity 编译的程序时,我出现以下错误:

Transaction simulation failed: Error processing Instruction 0: Program failed to complete 
    Program jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N invoke [1]
    Program log: pxKTQePwHC9MiR52J5AYaRtSLAtkVfcoGS3GaLD24YX
    Program log: sender account missing from transaction
    Program jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N consumed 200000 of 200000 compute units
    Program failed to complete: BPF program Panicked in solana.c at 285:0
    Program jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N failed: Program failed to complete

jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N 是程序的公钥,并且pxKTQePwHC9MiR52J5AYaRtSLAtkVfcoGS3GaLD24YX 是发送者的公钥。

我正在使用 @solana/solidity 库的一个分支,它公开了 Transaction 对象,以便可以由 Phantom 签名和发送钱包位于前端。导致错误的代码如下:

// Generate the transaction
const transaction = contract.transactions.send(...args);

// Add recent blockhash and fee payer
const recentBlockhash = (await connection.getRecentBlockhash()).blockhash;
transaction.recentBlockhash = recentBlockhash;
transaction.feePayer = provider.publicKey;

// Sign and send the transaction (throws an error)
const res = await provider.signAndSendTransaction(transaction);

我会尝试自己进一步调试,但我不确定从哪里开始。查找错误消息没有产生任何结果,并且错误消息的描述性不强。我不确定此错误是否发生在程序执行本身中,或者是否是事务对象的组成存在问题。如果这是程序执行中的问题,有没有办法将日志添加到我的 Solidity 代码中?如果是交易对象的问题,可能会遗漏什么?如何更好地调试此类问题?

感谢您的帮助。

编辑:尽管我没有更改任何提供的代码,但我现在遇到了不同的错误。现在的错误消息如下:

Phantom - RPC Error: Transaction creation failed. {code: -32003, message: 'Transaction creation failed.'}

不幸的是,这个错误消息比上一个错误消息更没有帮助。我不确定 Phantom Wallet 是否已更新,或者项目依赖项是否在某个时刻进行了更新,但考虑到这两个错误消息的模糊性以及我的代码均未更改的事实,我相信它们是由这些错误引起的由同一个问题。再次强调,任何帮助或调试提示都是值得赞赏的。

When attempting to make a call to a program compiled with @solana/solidity, I'm getting the following error:

Transaction simulation failed: Error processing Instruction 0: Program failed to complete 
    Program jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N invoke [1]
    Program log: pxKTQePwHC9MiR52J5AYaRtSLAtkVfcoGS3GaLD24YX
    Program log: sender account missing from transaction
    Program jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N consumed 200000 of 200000 compute units
    Program failed to complete: BPF program Panicked in solana.c at 285:0
    Program jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N failed: Program failed to complete

jdN1wZjg5P4xi718DG2HraGuxVx1mM7ebjXpxbJ5R3N is the program's public key and pxKTQePwHC9MiR52J5AYaRtSLAtkVfcoGS3GaLD24YX is the sender's public key.

I'm using a fork of the @solana/solidity library that exposes the Transaction object so that it can be signed and sent by Phantom Wallet on the front end. The code that results in the error is as follows:

// Generate the transaction
const transaction = contract.transactions.send(...args);

// Add recent blockhash and fee payer
const recentBlockhash = (await connection.getRecentBlockhash()).blockhash;
transaction.recentBlockhash = recentBlockhash;
transaction.feePayer = provider.publicKey;

// Sign and send the transaction (throws an error)
const res = await provider.signAndSendTransaction(transaction);

I would attempt to debug this further myself, but I'm not sure where to start. Looking up the error message hasn't yielded any results and the error message isn't very descriptive. I'm not sure if this error is occurring within the program execution itself or if it's an issue with the composition of the transaction object. If it is an issue within the program execution, is there a way for me to add logs to my solidity code? If it's an issue with the transaction object, what could be missing? How can I better debug issues like this?

Thank you for any help.

Edit: I'm getting a different error now, although I haven't changed any of the provided code. The error message is now the following:

Phantom - RPC Error: Transaction creation failed. {code: -32003, message: 'Transaction creation failed.'}

Unfortunately this error message is even less helpful than the last one. I'm not sure if Phantom Wallet was updated or if a project dependency was updated at some point, but given the vague nature of both of these error messages and the fact that none of my code has changed, I believe they're being caused by the same issue. Again, any help or debugging tips are appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

絕版丫頭 2025-01-25 15:53:20

我能够解决这个问题,虽然我遇到了另一个问题,但它与这个问题的内容无关,所以我将单独发布。

关于我的编辑,我发现错误消息之间的差异取决于我发送交易的方式。首先,我尝试使用 Phantom 的 .signAndSendTransaction() 方法发送它,这产生了第二条错误消息(在我的编辑下列出)。然后我尝试签名&手动发送交易,如下所示:

const signed = await provider.request({
  method: 'signTransaction',
  params: {
    message: bs58.encode(transaction.serializeMessage()),
  },
});

const signature = bs58.decode(signed.signature);
transaction.addSignature(provider.publicKey, signature);

await connection.sendRawTransaction(transaction.serialize())

这产生了我原来的帖子中包含的更详细的错误。一旦我意识到要查找什么,该错误消息确实很有帮助 - TransactionInstruction 上的 keys 字段中缺少发送帐户的公钥>交易。我将其添加到 我的 @solana/solidity 库的分支中,错误消失了。

简而言之,我能够调试此问题的方法是

  1. 使用 provider.request({ method: 'signTransaction' })connection.sendRawTransaction(transaction) 而不是 Phantom 的provider.signAndSendTransaction() 方法获取更详细的错误消息
  2. 记录交易对象并仔细检查指令

我希望这对将来的其他人有所帮助。

I was able to solve this issue, and although I've run into another issue it's not related to the contents of this question so I'll post it separately.

Regarding my edit, I found that the difference between the error messages came down to how I was sending the transaction. At first, I tried sending it with Phantom's .signAndSendTransaction() method, which yielded the second error message (listed under my edit). Then I tried signing & sending the transaction manually, like so:

const signed = await provider.request({
  method: 'signTransaction',
  params: {
    message: bs58.encode(transaction.serializeMessage()),
  },
});

const signature = bs58.decode(signed.signature);
transaction.addSignature(provider.publicKey, signature);

await connection.sendRawTransaction(transaction.serialize())

Which yielded the more verbose error included in my original post. That error message did turn out to be helpful once I realized what to look for -- the sending account's public key was missing from the keys field on the TransactionInstruction on the Transaction. I added it in my fork of the @solana/solidity library and the error went away.

In short, the way I was able to debug this was by

  1. Using provider.request({ method: 'signTransaction' }) and connection.sendRawTransaction(transaction) rather than Phantom's provider.signAndSendTransaction() method for a more verbose error message
  2. Logging the transaction object and inspecting the instructions closely

I hope this helps someone else in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文