1

Hello friends i get trouble i'm trying to swap with only route on jupiter this what is do :

const quoteResponse = data        
//    {
//        inputMint: 'So11111111111111111111111111111111111111112',  
//        inAmount: '1000000',
//        outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
//        outAmount: '160850',
//        otherAmountThreshold: '160850',
//        swapMode: 'ExactIn',
//        slippageBps: 0,
//        platformFee: null,
//        priceImpactPct: '0',
//        routePlan: [
//          { swapInfo: [Object], percent: 100 },
//          { swapInfo: [Object], percent: 100 }
//        ],
//        contextSlot: 299505353,
//        timeTaken: 0.014201567
//      }
const { swapTransaction } = await (
  await fetch('https://quote-api.jup.ag/v6/swap', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      quoteResponse,
      userPublicKey: wallet.publicKey.toString(),
      wrapAndUnwrapSol: true,
      computeUnitPriceMicroLamports  : "auto", 
    })
  })
).json();

const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');

var transaction = VersionedTransaction.deserialize(swapTransactionBuf);

transaction.sign([wallet.payer]);

const rawTransaction = transaction.serialize()

const txid = await connection.sendRawTransaction(rawTransaction, {
  skipPreflight: true,
  maxRetries: 10
});
console.log(txid);

But the problem is this :

enter image description here

How can i only call 1 instruction : Route ?? without red instructions ?

1 Answer 1

3

You can remove the Transfer and SyncNative instructions by changing wrapAndUnwrapSol to false. This will require your account to have wrapped SOL though. Then the transaction won't need to transfer between native and wrapped SOL for you.

For the CreateIdempotent, I don't think the Jupiter swap API gives you the ability to disable that.

Your best bet here might be to use the swap-instructions API instead, see Jupiter documentation. That gives you serialized instructions instead of a transaction, and then you put the transaction together yourself. Check the docs for a full code example, but here's part of it:

const instructions = await (
  await fetch('https://quote-api.jup.ag/v6/swap-instructions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      // quoteResponse from /quote api
      quoteResponse,
      userPublicKey: swapUserKeypair.publicKey.toBase58(),
    })
  })
).json();

if (instructions.error) {
  throw new Error("Failed to get swap instructions: " + instructions.error);
}

const {
  tokenLedgerInstruction, // If you are using `useTokenLedger = true`.
  computeBudgetInstructions, // The necessary instructions to setup the compute budget.
  setupInstructions, // Setup missing ATA for the users.
  swapInstruction: swapInstructionPayload, // The actual swap instruction.
  cleanupInstruction, // Unwrap the SOL if `wrapAndUnwrapSol = true`.
  addressLookupTableAddresses, // The lookup table addresses that you can use if you are using versioned transaction.
} = instructions;

Here you can see that the CreateIdempotent instruction will be in setupInstructions, so you could just ignore that one and create the transaction using the other instructions. This will of course only work if you already have the necessary token accounts!

I would also add that you almost certainly don't want to drop the compute budget instructions, since that'll make it less likely that your transaction lands successfully.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.