The transactions returned by the Brian API are compatible with the most common development tools, such as Solana-Web3.js.
The transaction contained in the API response is a serialized transaction. The steps to be taken are:
deserialize and sign the transaction
execute the transaction
The transaction returned in the API response follows the same format as the response from the Jupiter API. The deserialization, signing, and execution process are the same.
đ Check here for more info.
Deserialize, sign and execute the transaction(s)
Access the transaction object from the Brian API response (using the Brian ts SDK):
constbrian=newBrianSDK(options);constrequest=awaitbrian.transact({ prompt:"swap 1 sol for USDC on solana", address:"53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr",});console.log("transaction result:", request);// Create an empty array to store transactionsconsttxArray= [];// Loop through the requests and their stepsfor (constreqof request) {for (conststepofreq.data.steps) {// Push the step's data into the txArraytxArray.push(step.data); }}console.log("Transaction Array:", txArray);
Now, you can deserialize, sign, and execute the transaction(s)
// Get the latest blockhash before processing transactionsconstlatestBlockHash=awaitconnection.getLatestBlockhash();// Loop through each transaction data in txArrayfor (consttxDataof txArray) {try {// Deserialize the transactionconstswapTransactionBuf=Buffer.from(txData,"base64");consttransaction=VersionedTransaction.deserialize(swapTransactionBuf);console.log("Deserialized transaction:", transaction);// Sign the transactiontransaction.sign([wallet.payer]); // Ensure wallet.payer is a valid Keypair or signerconsole.log("Signed transaction:", transaction);// Execute the transactionconstrawTransaction=transaction.serialize();consttxid=awaitconnection.sendRawTransaction(rawTransaction, { skipPreflight:true, maxRetries:2, });awaitconnection.confirmTransaction({ blockhash:latestBlockHash.blockhash, lastValidBlockHeight:latestBlockHash.lastValidBlockHeight, signature: txid, });console.log(`Transaction successful: https://solscan.io/tx/${txid}`); } catch (error) {console.error("Error processing transaction:", error); } }} catch (error) {console.error("Error during request or transaction:", error);}