> For the complete documentation index, see [llms.txt](/llms.txt).

# Integrate Embedded Wallets with the Solana Blockchain in JavaScript

While using the Embedded Wallets Web SDK, you get a Solana provider with functions to help you make blockchain calls via [@solana/web3.js](https://solana.com/docs/clients/official/javascript#solana-web3js). Use this page for VanillaJS, Angular, and other frameworks.

## Chain details for Solana[​](#chain-details-for-solana "Direct link to Chain details for Solana")

- Mainnet
- Testnet
- Devnet

- Chain Namespace: SOLANA
- Chain ID: 0x1
- Public RPC URL: `https://api.mainnet-beta.solana.com` (avoid public RPC in production; prefer managed services)
- Display Name: Solana Mainnet
- Block Explorer Link: `https://explorer.solana.com`
- Ticker: SOL
- Ticker Name: Solana
- Logo: <https://images.toruswallet.io/solana.svg>

- Chain Namespace: SOLANA
- Chain ID: 0x2
- Public RPC URL: `https://api.testnet.solana.com` (avoid public RPC in production; prefer managed services)
- Display Name: Solana Testnet
- Block Explorer Link: `https://explorer.solana.com`
- Ticker: SOL
- Ticker Name: Solana
- Logo: <https://images.toruswallet.io/solana.svg>

- Chain Namespace: SOLANA
- Chain ID: 0x3
- Public RPC URL: `https://api.devnet.solana.com` (avoid public RPC in production; prefer managed services)
- Display Name: Solana Devnet
- Block Explorer Link: `https://explorer.solana.com?cluster=devnet`
- Ticker: SOL
- Ticker Name: Solana
- Logo: <https://images.toruswallet.io/solana.svg>

## For VanillaJS, Angular and other frameworks[​](#for-vanillajs-angular-and-other-frameworks "Direct link to For VanillaJS, Angular and other frameworks")

## Installation[​](#installation "Direct link to Installation")

To interact with the Solana blockchain, you can use [@solana/web3.js](https://solana.com/docs/clients/official/javascript#solana-web3js) library with Web3Auth along with `@web3auth/solana-provider` package.

- npm
- Yarn
- pnpm
- Bun

```
npm install --save @solana/web3.js @web3auth/solana-provider

```

```
yarn add @solana/web3.js @web3auth/solana-provider

```

```
pnpm add @solana/web3.js @web3auth/solana-provider

```

```
bun add @solana/web3.js @web3auth/solana-provider

```

## Initializing provider[​](#initializing-provider "Direct link to Initializing provider")

Using `solana` as `chainNamespace` while initializing `web3auth` will provide a Solana provider as **`web3auth.provider`** after successful authentication.

### Initializing and instantiating the Web3Auth SDK[​](#initializing-and-instantiating-the-web3auth-sdk "Direct link to Initializing and instantiating the Web3Auth SDK")

```
import { Web3Auth, WEB3AUTH_NETWORK } from '@web3auth/modal'

const web3AuthOptions: Web3AuthOptions = {
  clientId,
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
}

```

## Getting the Web3Auth provider[​](#getting-the-web3auth-provider "Direct link to Getting the Web3Auth provider")

After initializing Web3Auth, the next step is to initialize the provider and use it for your operations.

```
import { SolanaWallet } from '@web3auth/solana-provider'

// Initialize for PnP Web SDK
await web3auth.init()

// Trigger the login
await web3auth.connect()
// await web3auth.connectTo(); // For custom flow

// Get the provider
const provider = web3auth.provider

// Initialize Solana Wallet
const solanaWallet = new SolanaWallet(provider)

// Continue using the `solanaWallet`

```

## Get account and Balance[​](#get-account-and-balance "Direct link to Get account and Balance")

```
import {
  Connection,
  LAMPORTS_PER_SOL,
  PublicKey,
  SystemProgram,
  Transaction,
} from '@solana/web3.js'

const solanaWallet = new SolanaWallet(web3auth.provider)

// Get user's Solana public address
const accounts = await solanaWallet.requestAccounts()

const connectionConfig = await solanaWallet.request<string[], CustomChainConfig>({
  method: 'solana_provider_config',
  params: [],
})

const connection = new Connection(connectionConfig.rpcTarget)

// Fetch the balance for the specified public key
const balance = await connection.getBalance(new PublicKey(accounts[0]))

```

## Sign a transaction[​](#sign-a-transaction "Direct link to Sign a transaction")

```
import {
  Connection,
  LAMPORTS_PER_SOL,
  PublicKey,
  SystemProgram,
  Transaction,
} from '@solana/web3.js'

// solanaWallet is from above
const connectionConfig = await solanaWallet.request<string[], CustomChainConfig>({
  method: 'solana_provider_config',
  params: [],
})

const connection = new Connection(connectionConfig.rpcTarget)

const pubKey = await solanaWallet.requestAccounts()
const { blockhash } = await connection.getRecentBlockhash('finalized')

const TransactionInstruction = SystemProgram.transfer({
  fromPubkey: new PublicKey(pubKey[0]),
  toPubkey: new PublicKey(pubKey[0]),
  lamports: 0.01 * LAMPORTS_PER_SOL,
})

const transaction = new Transaction({
  recentBlockhash: blockhash,
  feePayer: new PublicKey(pubKey[0]),
}).add(TransactionInstruction)

const signedTx = await solanaWallet.signTransaction(transaction)
console.log(signedTx.signature)

```

## Sign all transactions[​](#sign-all-transactions "Direct link to Sign all transactions")

```
import {
  Connection,
  LAMPORTS_PER_SOL,
  PublicKey,
  SystemProgram,
  Transaction,
} from '@solana/web3.js'

// solanaWallet is from above
const connectionConfig = await solanaWallet.request<string[], CustomChainConfig>({
  method: 'solana_provider_config',
  params: [],
})

const connection = new Connection(connectionConfig.rpcTarget)

const pubKey = await solanaWallet.requestAccounts()
const { blockhash } = await connection.getRecentBlockhash('finalized')

// First transaction
const TransactionInstruction1 = SystemProgram.transfer({
  fromPubkey: new PublicKey(pubKey[0]),
  toPubkey: new PublicKey(pubKey[0]),
  lamports: 0.01 * LAMPORTS_PER_SOL,
})

// Second transaction
const TransactionInstruction2 = SystemProgram.transfer({
  fromPubkey: new PublicKey(pubKey[0]),
  toPubkey: new PublicKey(pubKey[0]),
  lamports: 0.02 * LAMPORTS_PER_SOL,
})

const transaction1 = new Transaction({
  recentBlockhash: blockhash,
  feePayer: new PublicKey(pubKey[0]),
}).add(TransactionInstruction1)
const transaction2 = new Transaction({
  recentBlockhash: blockhash,
  feePayer: new PublicKey(pubKey[0]),
}).add(TransactionInstruction2)

const signedTx = await solanaWallet.signAllTransactions([transaction1, transaction2])
console.log(signedTx)

```

## Sign and Send Transaction[​](#sign-and-send-transaction "Direct link to Sign and Send Transaction")

```
import {
  Connection,
  LAMPORTS_PER_SOL,
  PublicKey,
  SystemProgram,
  Transaction,
} from '@solana/web3.js'

// solanaWallet is from above
const connectionConfig = await solanaWallet.request<string[], CustomChainConfig>({
  method: 'solana_provider_config',
  params: [],
})

const connection = new Connection(connectionConfig.rpcTarget)

const accounts = await solanaWallet.requestAccounts()
const block = await connection.getLatestBlockhash('finalized')

const TransactionInstruction = SystemProgram.transfer({
  fromPubkey: new PublicKey(accounts[0]),
  toPubkey: new PublicKey(accounts[0]),
  lamports: 0.01 * LAMPORTS_PER_SOL,
})

const transaction = new Transaction({
  blockhash: block.blockhash,
  lastValidBlockHeight: block.lastValidBlockHeight,
  feePayer: new PublicKey(accounts[0]),
}).add(TransactionInstruction)

const { signature } = await solanaWallet.signAndSendTransaction(transaction)

console.log(signature)

```

## Sign a message[​](#sign-a-message "Direct link to Sign a message")

```
import {
  Connection,
  LAMPORTS_PER_SOL,
  PublicKey,
  SystemProgram,
  Transaction,
} from '@solana/web3.js'

// solanaWallet is from above
const msg = Buffer.from('Test Signing Message', 'utf8')
const result = await solanaWallet.signMessage(msg)
console.log(result.toString())

```

## Fetch user's private key[​](#fetch-users-private-key "Direct link to Fetch user's private key")

`solana_privateKey` is used to fetch the private key of the logged in user. It is only available for `in-app` adapters like `auth`.

```
// Assuming user is already logged in.
async getPrivateKey() {
  const privateKey = await web3auth.provider.request({
    method: "solana_privateKey"
  });

  // Do something with privateKey
}

```
