2

Jupiter Swap V6 Problem with commission.

Hello, I have a problem. I made a node js script to send a swap through the jupiter ag platform.

My transaction is successful, but the solscan page displays No Data and there is no transaction, it does not go through.

As I understand it, the error is that in my transaction the commission is minimal and therefore the transaction does not go through. Out of 50 transactions, only 1-2 are successful for me. I have a referral API key but I don’t understand how to install it to make a commission.

Please help me how can I set a commission for a transaction, I looked at the documentation but I still don’t understand how to set it correctly in order to set a commission for a transaction.

https://station.jup.ag/docs/apis/adding-fees

https://station.jup.ag/docs/apis/swap-api#6-get-the-serialized-transactions-to-perform-the-swap

Here is an example transaction: https://solscan.io/tx/gz8wng1SqCgkaYZsZBMzt5GwZESZ41DQHuycTLENCKmj5empCLyVoJoPvwzvcbVkNRB5MKZQHVaa8eNk8eCz3Ww Solscan

Here is my code that I use to make a swap:

import { Connection, Keypair, PublicKey, VersionedTransaction } from '@solana/web3.js';
import { createJupiterApiClient } from '@jup-ag/api';
import { Wallet } from '@project-serum/anchor';
import axios from 'axios';
import bs58 from 'bs58';
import logger from './logger.js';
import { cfgSwap, cfgScript, cfgDeal } from './config.js';

const jupiterQuoteApi = createJupiterApiClient();
const wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(cfgSwap.PRIVATE_KEY || '')));
const connection = new Connection(cfgScript.RPC_ENDPOINT, { wsEndpoint: cfgScript.RPC_WEBSOCKET });
const feeAccount = "FTECPy8Qt1JtJwvE7p3qPuvVLWB";


async function swap(input_mint, output_mint, amount) {
    const new_amount = amount * cfgDeal.SOL_DIVIDE;
    const slippagebps = cfgDeal.MAX_SLIPPAGE_TOLERANCE;
    const extrafee = cfgDeal.EXTRA_FEE;

    const quote = await jupiterQuoteApi.quoteGet({
        inputMint: input_mint,
        outputMint: output_mint,
        amount: new_amount,
        slippageBps: slippagebps,
        swapMode: 'ExactOut',
        onlyDirectRoutes: false,
        asLegacyTransaction: false,
    });

    const swapTransaction = await jupiterQuoteApi.swapPost({
        swapRequest: {
            quoteResponse: quote,
            userPublicKey: wallet.publicKey.toBase58(),
            dynamicComputeUnitLimit: true,
            wrapAndUnwrapSol: true,
            prioritizationFeeLamports: 'auto',
            preflightCommitment: 'processed',
            
            },
        });
    
        logger.info('[post_swap] Attempting to send a request.');
        const swapTransactionBuffer = Buffer.from(swapTransaction.swapTransaction, "base64");
        const transaction = VersionedTransaction.deserialize(swapTransactionBuffer);
        transaction.sign([wallet.payer])
    
        var tryAgain = true;
        var objSignatureStatusResult;
        var maxTriesCounter = 0;
        var maxTries = 5;
        logger.info('[transaction] Attempting to create a transaction');
        
        while (tryAgain) {
            maxTriesCounter++;
            const rawTransaction = transaction.serialize();
            const txid = await connection.sendRawTransaction(rawTransaction, {
            skipPreflight: true,
            maxRetries: 5,
            preflightCommitment: 'confirmed',
            });
    
            logger.info(`Swap successful! Transaction ID: ${txid}`);
            logger.info(`View the transaction Sosclan: https://solscan.io/tx/${txid}`);
    
            await new Promise(r => setTimeout(r, 1500));
    
            const result = await connection.getSignatureStatus(txid, {
            searchTransactionHistory: true,
            });
            objSignatureStatusResult = JSON.parse(JSON.stringify(result));
            if (objSignatureStatusResult.value !== null) tryAgain = false;
            if (maxTriesCounter>maxTries) tryAgain = false;
            return txid;
        }
}



async function swapRun() {
    await swap(
        "So11111111111111111111111111111111111111112",
        "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
        0.001
    );
}

swapRun();

0

Your Answer

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

Browse other questions tagged or ask your own question.