⌨️Submit Order

Below we provide some example code for making a trade on Bebop.

Bebop submits order on chain having received maker and taker signatures. This means that Bebop pays the network (gas) fees as they are already included in the price. This is the default mode.

Bebop web interface users and most API users would choose Bebop's default mode where user signs the order transaction and Bebop sends it on-chain.

In some cases, API users may need to submit the transaction themselves, and we have a mode for that too.

Example

import axios from "axios";
import bs58 from "bs58";
import { createKeyPairFromPrivateKeyBytes, signBytes, getTransactionDecoder } 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 SOL_TEST_ACCOUNT = await createKeyPairFromPrivateKeyBytes(bs58.decode(privateKey).slice(0, 32));
    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: true
        }
    })).data
    console.log(quote)

    // Sign Order
    const tx = getTransactionDecoder().decode(Buffer.from(quote.solana_tx, "base64"));
    const signature = await signBytes(SOL_TEST_ACCOUNT.privateKey, tx.messageBytes);

     // Send Transaction
    let response = (await axios.post(`https://api.bebop.xyz/pmm/solana/v3/order`, {
        signature: bs58.encode(signature),
        quote_id: quote.quoteId,
    })).data
    console.log(response)

}

sendTx();

Last updated