# Solana

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:

1. deserialize and sign the transaction
2. execute the transaction

{% hint style="success" %}
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](https://station.jup.ag/docs/apis/swap-api#6-deserialize-and-sign-the-transaction).
{% endhint %}

#### Deserialize, sign and execute the transaction(s)

Access the transaction object from the Brian API response (using the Brian ts SDK):

```typescript

const brian = new BrianSDK(options);

const request = await brian.transact({
  prompt: "swap 1 sol for USDC on solana",
  address: "53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr",
});
console.log("transaction result:", request);

// Create an empty array to store transactions
const txArray = [];

// Loop through the requests and their steps
for (const req of request) {
  for (const step of req.data.steps) {
    // Push the step's data into the txArray
    txArray.push(step.data);
  }
}

console.log("Transaction Array:", txArray);

```

Now, you can deserialize, sign, and execute the transaction(s)

```typescript
// Get the latest blockhash before processing transactions
  const latestBlockHash = await connection.getLatestBlockhash();

  // Loop through each transaction data in txArray
  for (const txData of txArray) {
    try {
      // Deserialize the transaction
      const swapTransactionBuf = Buffer.from(txData, "base64");
      const transaction = VersionedTransaction.deserialize(swapTransactionBuf);
      console.log("Deserialized transaction:", transaction);

      // Sign the transaction
      transaction.sign([wallet.payer]); // Ensure wallet.payer is a valid Keypair or signer
      console.log("Signed transaction:", transaction);

      // Execute the transaction
      const rawTransaction = transaction.serialize();
      const txid = await connection.sendRawTransaction(rawTransaction, {
        skipPreflight: true,
        maxRetries: 2,
      });
      await connection.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);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.brianknows.org/brian-api/apis/transaction/transactions-flow/solana.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
