繁体   English   中英

交易模拟失败:错误处理指令0:自定义程序错误:0x0

[英]Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0

我正在使用 raydium sdk 来增加货币对的流动性,我已经创建了交易,但是每当它从 phatom 钱包获得批准时,就会发生如下所述的错误。

Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]
Program log: Allocate space for the associated token account
Program 11111111111111111111111111111111 invoke [2]
Allocate: account Address { address: 7hLSYuEhn7t1P62n9gpv2aG8peTtLvjSRKqSsk2MXa91, base: None } already in use
Program 11111111111111111111111111111111 failed: custom program error: 0x0
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 8366 of 200000 compute units
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: custom program error: 0x0

我需要帮助来解决这个问题,因为我无法确定问题所在。

下面是我在 Raydium SDK 的帮助下在 ReactJS 中使用的 function 代码。

 const tokenReq = await solanaConnectionObj.getTokenAccountsByOwner(publicKey, { programId: TOKEN_PROGRAM_ID })
  const parsedTokenAccounts = await solanaConnectionObj.getParsedTokenAccountsByOwner(publicKey, {
    programId: TOKEN_PROGRAM_ID,
  })

  const tokenAccounts = []
  for (let index = 0; index < tokenReq.value.length; index++) {
    const rawResult = SPL_ACCOUNT_LAYOUT.decode(tokenReq.value[index].account.data)
    if (
      rawResult.mint.toString().toLowerCase() === tokenObj0.mint.toString().toLowerCase() ||
      rawResult.mint.toString().toLowerCase() === tokenObj1.mint.toString().toLowerCase() ||
      rawResult.mint.toString().toLowerCase() === RAYDIUM_LP_TOKEN_ACCOUNT.toLowerCase()
    ) {
      tokenAccounts.push({
        accountInfo: rawResult,
        pubkey: publicKey,
      })
    }
  }

  const transactionData = await Liquidity.makeAddLiquidityTransaction({
    poolKeys: RAYDIUM_POOL,
    userKeys: {
      tokenAccounts: tokenAccounts,
      owner: publicKey,
      payer: publicKey,
    },
    fixedSide: 'a',
    amountInB: new TokenAmount(tokenObj1, amount0.toWei().toString()),
    amountInA: new TokenAmount(tokenObj0, amount1.toWei().toString()),
    connection: solanaConnectionObj,
  })

  transactionData.transaction.feePayer = publicKey
  const latestBlockHashResult = await solanaConnectionObj.getRecentBlockhash('confirmed')

  transactionData.transaction.recentBlockhash = latestBlockHashResult.blockhash

  const signedTxs = await signTransaction(transactionData.transaction)
  const txids = await solanaConnectionObj.sendRawTransaction(signedTxs.serialize())

  return transactionData

如果不了解有关makeAddLiquidityTransaction端点的更多详细信息,很难给出完整的答案,但您看到的错误是:

Allocate: account Address { address: 7hLSYuEhn7t1P62n9gpv2aG8peTtLvjSRKqSsk2MXa91, base: None } already in use

在调用关联令牌帐户程序期间,该程序为用户创建新的令牌帐户。

在您的情况下,错误表明该帐户已在使用中,因此该交易包含创建关联令牌帐户的不必要调用。 这可能是 Raydium SDK 中的 bug,或者RAYDIUM_LP_TOKEN_ACCOUNT地址不正确,导致 SDK 认为您没有正确的 LP 令牌帐户。 如果需要,您可以通过删除第一条指令来解决这个问题。

有关关联令牌帐户计划的更多背景信息,请访问https://spl.solana.com/associated-token-account

当合约代码逻辑被破坏时,交易模拟失败错误(在以太坊中也是如此)发生。 您要么将错误的 arguments 传递给客户端的 function 调用(例如,它需要字符串但您传递了一个数字),要么在客户端以错误的方式调用函数(确保检查客户端包的 api)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM