Saros Super App

Integrate Saros Super App easily through our developer guide down here

Solana DApps Integration

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

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

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

To disconnect Saros Extension, please use:

window.saros.disconnect()

To experience functions

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

Get Current Account

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

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

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

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

return Promise<boolean>

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

To handle events

List of events

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

Last updated