Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7939

VersionedTransaction issue

$
0
0

I'm trying to do quick swap with solana actions and Jupiter swap API V6. My goal is to swap sol to usdc. Once in a while it works with the same code. As well the simulation goes well. As you can see below I have got the VersionedTransaction transaction from quote-api and event try to rebuild this transaction with addressTableLookups but in the and I have got an error:

Error: Failed to get account keys because address table lookups were not resolvedat MessageV0.getAccountKeys (webpack-internal:///(rsc)/./node_modules/@solana/web3.js/lib/index.esm.js:1025:13)at TransactionMessage.decompile (webpack-internal:///(rsc)/./node_modules/@solana/web3.js/lib/index.esm.js:2072:33)at prepareVersionedTransaction (webpack-internal:///(rsc)/./node_modules/@solana/actions/lib/esm/createPostResponse.js:48:83)

export async function swap(account: PublicKey, connection: Connection): Promise < VersionedTransaction > {const coinToAddress = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";const coinFromAddress = "So11111111111111111111111111111111111111112";const amountToSwap = 1000000000;const quoteResponse = await (    await fetch(`https://quote-api.jup.ag/v6/quote?inputMint=${coinFromAddress}&outputMint=${coinToAddress}&amount=${amountToSwap}&slippageBps=50`)).json();console.log(quoteResponse)const transaction = await (    await fetch('https://quote-api.jup.ag/v6/swap', {        method: 'POST',        headers: {'Content-Type': 'application/json'        },        body: JSON.stringify({            quoteResponse,            userPublicKey: account.toString(),            wrapUnwrapSOL: true,        })    })).json();const { swapTransaction } = transaction;const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');var versionedTransaction: VersionedTransaction = VersionedTransaction.deserialize(swapTransactionBuf);const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();// get lookup tableconst atls = versionedTransaction.message.addressTableLookups.map(address => address.accountKey)const atlsAccount = await Promise.all(    atls.map(async (alt): Promise<AddressLookupTableAccount> => {        const account = (await connection.getAddressLookupTable(alt)).value;        if (!account) {            console.log("Could not retrieve address lookup table", alt.toBase58());            exit(42);        }        return account;    }));console.log(atlsAccount)const decompiledMessage = TransactionMessage.decompile(versionedTransaction.message, { addressLookupTableAccounts: atlsAccount });decompiledMessage.payerKey = accountdecompiledMessage.recentBlockhash = blockhashconst newVersionedTransaction = new VersionedTransaction(    decompiledMessage.compileToV0Message(atlsAccount));console.log(newVersionedTransaction);console.log("---------------------------------simulation----------------------------------------------------");const simulation = await connection.simulateTransaction(newVersionedTransaction)const tx =  await connection.sendTransaction(newVersionedTransaction)console.log(simulation)return newVersionedTransaction;}

Viewing all articles
Browse latest Browse all 7939

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>