Skip to main content

Torus Solana Adapter

@web3auth/torus-solana-adapter

Torus solana adapter allows to connect with torus wallet for solana blockchain. You can read more about torus wallet here.

Basic Details

Adapter Name: torus-solana

Package Name: @web3auth/torus-solana-adapter

authMode: DAPP

chainNamespace: SOLANA

Default: YES

Installation

npm install --save @web3auth/torus-solana-adapter

Arguments

Parametertype
chainConfigCustomChainConfig
adapterSettingsTorusCtorArgs
loginSettingsLoginParams
initParamsOmit<TorusParams, "network">
clientId?string
sessionTime?number
web3AuthNetwork?WEB3AUTH_NETWORK_TYPE

Custom Chain Config

chainConfig

warning

While you can pass your chainConfig, it is not required since you can directly pass it over to the Web3Auth/ Web3AuthNoModal configuration while instantiating it.

Read more about it in their respective sections:

warning

If you do pass chainConfig in an Adapter, it overwrites the chainConfig passed over to the Web3Auth/ Web3AuthNoModal constructor.

Change Adapter Settings

You can change the adapter settings by calling the setAdapterSettings() function on the adapter instance.

Arguments

Parametertype
clientId?string
sessionTime?number
chainConfig?CustomChainConfig
web3AuthNetwork?WEB3AUTH_NETWORK_TYPE

Example

import { SolanaWalletAdapter } from "@web3auth/torus-solana-adapter";
const solanaWalletAdapter = new SolanaWalletAdapter({
adapterSettings: {
modalZIndex: 99999,
},
loginSettings: {
loginProvider: "google",
},
initParams: {
buildEnv: "testing",
},
chainConfig: {
chainNamespace: CHAIN_NAMESPACES.SOLANA,
rpcTarget: "https://api.mainnet-beta.solana.com",
blockExplorer: "https://explorer.solana.com",
chainId: "0x1", // Please use 0x1 for Mainnet, 0x2 for Testnet, 0x3 for Devnet
displayName: "Solana Mainnet Beta",
ticker: "sol",
tickerName: "solana",
},
clientId:
"BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ",
sessionTime: 3600, // 1 hour in seconds
web3AuthNetwork: "sapphire_mainnet",
});

// it will add/update the torus-solana adapter in to web3auth class
web3auth.configureAdapter(solanaWalletAdapter);

// you can also change the adapter settings by calling the setAdapterSettings() function on the adapter instance

solanaWalletAdapter.setAdapterSettings({
sessionTime: 86400, // 1 day in seconds
chainConfig: {
chainNamespace: CHAIN_NAMESPACES.SOLANA,
chainId: "0x1",
rpcTarget: "https://rpc.ankr.com/solana", // This is the public RPC we have added, please pass on your own endpoint while creating an app
},
web3AuthNetwork: "sapphire_mainnet",
});