🔌Self Execute Order

To retrieve a quote from the API that can be independently executed, set the gasless=false when retrieving a quote. In this case, Bebop will not handle the execution of the transaction. As such, gas fees will not be included in the quote.

Different pricing applies to self executed orders.

circle-info

For a successful trade, ensure that the transaction is included on chain before the expiry in the quote response.

For use cases where validations are not required or are restrictive at quote time, the skip_validation=true flag can be passed. This will disable approvals, gas estimate and balance checks.

Example - Sending a transaction

import axios from "axios";
import bs58 from "bs58";
import {
  createSolanaRpc, sendAndConfirmTransactionFactory, getSignatureFromTransaction,
  createKeyPairFromPrivateKeyBytes, getTransactionDecoder, signTransaction,
  createSolanaRpcSubscriptions
} from "@solana/kit";

// Trade Info (Insert your values)
const privateKey = ""
const publicKey = "" // user address
const sellToken = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" // USDC
const sellAmount = "100000" // 0.1 USDC
const buyToken = "So11111111111111111111111111111111111111112" // SOL


// Getting quote and submitting it onchain
async function sendTx() {
    const RPC = createSolanaRpc("https://api.mainnet-beta.solana.com");
    const WSS = createSolanaRpcSubscriptions("wss://api.mainnet-beta.solana.com/");
    const SOL_TEST_ACCOUNT = await createKeyPairFromPrivateKeyBytes(bs58.decode(privateKey).slice(0, 32));

    // Get quote
    let quote = (await axios.get("https://api.bebop.xyz/pmm/solana/v3/quote", {
        params: {
            buy_tokens: buyToken,
            sell_tokens: sellToken,
            sell_amounts: sellAmount,
            taker_address: publicKey,
            gasless: false
        }
    })).data
    console.log(quote)

    const tx = getTransactionDecoder().decode(Buffer.from(quote.solana_tx, "base64"));
    const signedTx = await signTransaction([SOL_TEST_ACCOUNT], tx);

    const {value: { blockhash, lastValidBlockHeight }} = await RPC.getLatestBlockhash().send();
    const signedTxWithLifetime = {
        ...signedTx, lifetimeConstraint: { blockhash, lastValidBlockHeight},
    };
    const sendAndConfirm = sendAndConfirmTransactionFactory({
        rpc: RPC, rpcSubscriptions: WSS,
    });
    await sendAndConfirm(signedTxWithLifetime, {
        commitment: "confirmed", preflightCommitment: "processed",
    });
    const sig = getSignatureFromTransaction(signedTxWithLifetime);
    console.log("Sent tx:", sig);
}

sendTx();

Last updated