⌨️Submit Order
Below we provide some example code for making a trade on Bebop.
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