# Saros Super App

## Solana DApps Integration <a href="#solana-dapps-integration" id="solana-dapps-integration"></a>

Welcome to Saros Wallet Developer Guide. This documentation contains guides for developers to get started developing on Saros Wallet

### The easiest way to detect to Saros Wallet <a href="#the-easiest-way-to-detect-to-saros-wallet" id="the-easiest-way-to-detect-to-saros-wallet"></a>

Check if the provider is `window.saros`, if not, please replace it with the exclusive Saros Wallet provider `window.saros`.

```
if(window.saros){
    console.log('Saros Extension is installed!');
}
```

```
function getProvider() {
  const provider = window.saros;
  if (!provider) {
    return window.open('');
  }
  return provider;
}
```

***

### To connect Saros Extension Wallet <a href="#to-connect-saros-extension-wallet" id="to-connect-saros-extension-wallet"></a>

To connect Saros Extension means to access the user's account(s).

```
// Connect & get accounts
window.saros.request({method: 'sol_accounts'});

// Alias for connection
window.saros.request({method: 'sol_requestAccounts'});​

//Check if dapp connected
window.saros.isConnected();
```

### To disconnect Saros Extension Wallet <a href="#to-disconnect-saros-extension-wallet" id="to-disconnect-saros-extension-wallet"></a>

To disconnect Saros Extension, please use:

```
window.saros.disconnect()
```

### To experience functions <a href="#to-experience-functions" id="to-experience-functions"></a>

Once your account is connected, let's start experiencing more functions.‌

#### Get Current Account <a href="#get-current-account" id="get-current-account"></a>

return `Promise<Array[String]>`

* If wallet can not be found, return `[]` instead of `throw Error`

```
window.saros.request({ method: 'sol_accounts' }).then(accounts => {
  if (accounts[0]) {
    // Do something with accounts
  } else {
    // Wallet not found
  }
})
```

#### Check wallet whether exists or not <a href="#check-wallet-whether-exists-or-not" id="check-wallet-whether-exists-or-not"></a>

return `Promise<{data: Boolean}>`

```
window.saros.request({ method: 'has_wallet', params: ['solana'] })
// Example
window.saros.request({ method: 'has_wallet', params: ['solana'] }).then(() => {
  // Wallet Exists
}).catch(e => { 
  // Wallet not found
})
```

#### Sign Transaction <a href="#sign-transaction" id="sign-transaction"></a>

In order to send a message for the user to sign, a web application must:

1. Provide a **hex** or **UTF-8** encoded string as a Uint8Array.

return: \`Promise<({signature: base58, publicKey: PublicKey})>

```
// Example Sign Transaction
const signature = window.saros.request({
    method: 'sol_sign',
    params: [<Transaction>]
}).then(({publicKey, signature}) => {
	//Do something with publicKey and signature
});
```

#### **Signing and Sending Multiple Transactions** <a href="#signing-and-sending-multiple-transactions" id="signing-and-sending-multiple-transactions"></a>

```
const solSignAllTransaction = async () => {
  try {
    const pubKey = new PublicKey(solanaAccount)
    const txs = new Transaction().add(SystemProgram.transfer({
      fromPubkey: pubKey,
      toPubkey: pubKey,
      lamports: LAMPORTS_PER_SOL / 100
    }))

    txs.recentBlockhash = (await cnn.getLatestBlockhash()).blockhash
    txs.feePayer = pubKey

    const transactions = [txs, txs, txs]

    const result = await window.saros.request({
      method: 'sol_signAllTransactions',
      params: [transactions]
    })
    return result
  } catch (err) {
    console.log({ err })
  }
}
```

#### Verify Signature <a href="#verify-signature" id="verify-signature"></a>

return `Promise<boolean>`

```
window.saros.request({
  method: 'sol_verify',
  params: [signature, msg]
})
```

***

### To handle events <a href="#to-handle-events" id="to-handle-events"></a>

#### List of events <a href="#list-of-events" id="list-of-events"></a>

Currently we only support some action event from wallet extension

```
window.saros.on('event_name', callback);
​//Example
window.saros.on('close', () => window.location.reload());
window.saros.on('accountsChanged', () => window.location.reload());
```

| Events     | Trigger                                |
| ---------- | -------------------------------------- |
| disconnect | Receive when disconnect from Extension |

| Method               | Description           |
| -------------------- | --------------------- |
| on(event, callback)  | Add event listener    |
| off(event, callback) | Remove event listener |


---

# 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.saros.xyz/integration-1/saros-super-app.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.
