The FluxBeam Swap API allows developers and users to retrieve swap quotes and pre-built transactions to speed up integration.
Quote
The quote API will return the expected output amount and slippage amount based on the provided input amount & token mints.
Currently, the API only returns pools on FluxBeam DEX.
Example
constinMint="So11111111111111111111111111111111111111112"constoutMint="FLUXBmPhT3Fd1EDVFdg46YREqHBeNypn1h4EbnTzWERX"constamount="1000000000"constslippageBPS="50"const uri = `https://api.fluxbeam.xyz/v1/quote?inputMint=${inMint}&outputMint=${outMint}&amount=${amount}&slippageBps=${slippageBPS}`
constquote=await (awaitfetch(uri)).json()
Swap Transaction
The Transaction endpoint returns a pre-built transaction that is ready to be signed by the payer wallet based on the quote provided.
The swap transaction includes the following instructions:
Priority Fee Price & Units
Input & Output associated token account creation
Wrap & Unwrap of SOL accounts
Example
import { Connection, Keypair, VersionedTransaction } from'@solana/web3.js';consturi=`https://api.fluxbeam.xyz/v1/swap/transaction`constresp=await(awaitfetch(uri, { method:"POST", headers: {"Content-Type":"application/json"}, body:JSON.strinfgify({// })})).json()//Decode the transaction from base64constswapTransactionBuf=Buffer.from(resp.transaction,'base64');consttransaction=VersionedTransaction.deserialize(swapTransactionBuf);console.log("Transaction",transaction);//Sign the transaction with the payer wallettransaction.sign([wallet.payer]);//Execute the transactionconstclient=newConnection('{RPC_URL}');constsig=client.sendRawTransaction(transaction.serialize(), {maxRetries:3, skipPreflight:true})console.log("Transaction Signature:", sig)
Swap Instruction
The instruction endpoint will return the FluxBeam swap instruction for a given quote. The instruction should be included within a transaction that handles the priority fee & associated token account calls.
Example
import { Connection, Keypair, Transaction} from'@solana/web3.js';consturi=`https://api.fluxbeam.xyz/v1/instruction`constresp=await(awaitfetch(uri, { method:"POST", headers: {"Content-Type":"application/json"}, body:JSON.strinfgify({ quote,//Response from /quote userPublicKey:"{PAYER_WALLET_ADDRESS}", priorityFeeLamports:100, wrapAndUnwrapSol:true })})).json()//Decode the instructionconstix=newTransactionInstruction({ programId:newPublicKey(instruction.programId), keys:instruction.accounts.map((key) => ({ pubkey:newPublicKey(key.Pubkey), isSigner:key.IsSigner, isWritable:key.IsWritable, })), data:Buffer.from(instruction.data,"base64"),//Create new transactionconst transaction =newTransaction();//Add pre-swap instructions// transaction.add(ataIx)//Add swap instructiontransaction.add(ix)//Add post-swap instructions// transaction.add(wSolClose)console.log("Transaction",transaction);//Sign the transaction with the payer wallettransaction.sign([wallet.payer]);//Execute the transactionconst client= new Connection('{RPC_URL}');const sig = client.sendRawTransaction(transaction.serialize(), {maxRetries:3, skipPreflight:true})console.log("Transaction Signature:", sig)