[英]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.