Skip to main content

Using PnP Web No Modal SDK

Once you've installed and successfully initialized Web3AuthNoModal, you can use it to authenticate your users. Further, you can use the native provider given by Web3AuthNoModal to connect the users to the respective blockchain network.

Natively, the instance of Web3AuthNoModal (referred to as web3auth in our examples) returns the following functions:

  • connectTo() - Logging in the User with the given Wallet Adapter and respective Login Parameters.
  • getUserInfo() - Getting the User's Information.
  • enableMFA() - Enable Multi Factor Authentication for the user.
  • authenticateUser() - Getting the idToken from Web3Auth.
  • addChain() - Add chain config details to the connected adapter.
  • switchChain() - Switch chain as per chainId already added to the chain config.
  • logout() - Logging out the User.
  • getAdapter() - Retrieve a specific wallet adapter by its name.
  • configureAdapter() - Configure a new or existing adapter.
  • clearCache() - Clear cached session information.

Additionally, the following methods and properties are available to get or modify information about the current state of the instance:

  • connected - Returns true or false depending on whether the user is connected or not.
  • status - Returns the current status of the web3auth instance.
  • provider (getter/setter) - Returns or sets the currently connected provider to the web3auth instance.
  • connectedAdapterName - Returns the name of the currently connected adapter.

You can also extend functionality by using the following plugin management functions:

  • addPlugin() - Add a plugin to extend the functionality of the Web3Auth instance.
  • getPlugin() - Retrieve an added plugin by name.

Finally, with the Wallet Services Plugin, you can enable additional functionalities like:

  • showWalletUI() - Show Wallet UI Screen.
  • initiateTopup() - Initiate Topup for the user.
  • showWalletConnectScanner() - Show WalletConnect QR Code Scanner.

Logging in the User

connectTo()

To log a user in the Web3Auth Plug and Play No Modal SDK, you need to call the connectTo() function. This function helps you customize the login process according to your own needs, by taking the following parameters:

VariableDescription
walletNameWallet Adapter you want to use for logging in your user. It accepts WALLET_ADAPTER_TYPE.
loginParams?Login parameters specific to your wallet adapter. Although this is defined as a generic type T, you can use AuthLoginParams as a reference for typical parameters.

Returns

connectTo<T>(walletName: WALLET_ADAPTER_TYPE, loginParams?: T): Promise<IProvider | null>;
  • On successful login, the connectTo() function returns a IProvider instance. This instance contains the respective provider corresponding to your selected blockchain. You can use this provider to connect your user to the blockchain and make transactions.

  • On unsuccessful login, this function will return a null value.

Usage

import { WALLET_ADAPTERS } from "@web3auth/base";
// inside your async function with on click handler
const web3authProvider = await web3auth.connectTo(WALLET_ADAPTERS.AUTH, {
loginProvider: "google",
});
tip

You can use the connectTo() function to connect to the custom authentication verifiers you might have deployed on the Web3Auth Dashboard, as well as the default ones that Web3Auth provides. For the default verifiers, you don't need to provide any additional parameters, just pass on the login provider type.

tip

Read more about connecting your users with the selected blockchain in the Providers SDK Reference.

Wallet Adapter Name

walletName

VariableValueDescription
MULTI_CHAIN_ADAPTERSAUTH, WALLET_CONNECT_V2, SFAMulti-chain adapters for Auth.
SOLANA_ADAPTERSAUTH, WALLET_CONNECT_V2, SFA, TORUS_SOLANASolana adapters for Auth.
EVM_ADAPTERSAUTH, WALLET_CONNECT_V2, SFA, TORUS_EVM, COINBASEEVM adapters for Auth.
WALLET_ADAPTERSAUTH, WALLET_CONNECT_V2, SFA, TORUS_SOLANA, TORUS_EVM, COINBASEAll wallet adapters for Auth.
WALLET_ADAPTER_TYPEWALLET_ADAPTERS[keyof WALLET_ADAPTERS]Type for wallet adapters.
SOLANA_ADAPTER_TYPESOLANA_ADAPTERS[keyof SOLANA_ADAPTERS]Type for Solana adapters.
EVM_ADAPTER_TYPEEVM_ADAPTERS[keyof EVM_ADAPTERS]Type for EVM adapters.
MULTI_CHAIN_ADAPTER_TYPEMULTI_CHAIN_ADAPTERS[keyof MULTI_CHAIN_ADAPTERS]Type for multi-chain adapters.
ADAPTER_NAMES{ [adapter: string]: string }Adapter names for Auth.

Login Parameters

loginParams

The loginParams are specific for each and every function. Please refer to the Adapters SDK Reference to know more about the login parameters specific to each wallet adapter.

For auth-adapter which enables social logins, you can refer to the following loginParams.

LoginSettings
VariableDescription
loginProviderloginProvider sets the oauth login method to be used. You can use any of the valid loginProvider from the supported list.
mfaLevelYou can set the mfaLevel to customize when mfa screen should be shown to user. It currently accepts 4 values:- - 'default': Setting mfa level to default will present mfa screen to user on every third login. - 'optional': Setting mfa level to default will present mfa screen to user on every login but user can skip it. - 'mandatory': Setting mfa level to mandatory will make it mandatory for user to setup mfa after login. - 'none': Setting mfa level to none will make the user skip the mfa setup screen Defaults to none @defaultValue none
getWalletKeyThis option is for internal use only in torus wallet and has no effect on user's login on other dapps. Defaults to false @defaultValue false @internal
extraLoginOptionsextraLoginOptions can be used to pass standard oauth login options to loginProvider. For ex: you will have to pass login_hint as user's email and domain as your app domain in extraLoginOptions while using email_passwordless loginProvider
dappShareCustom Logins can get a dapp share returned to them post successful login. This is useful if the dapps want to use this share to allow users to login seamlessly dappShare is a 24 word seed phrase
curveThis curve will be used to determine the public key encoded in the jwt token which returned in getUserInfo function after user login. You can use that public key from jwt token as a unique user identifier in your backend. - 'secp256k1': secp256k1 based pub key is added as a wallet public key in jwt token to use. - 'ed25519': ed25519 based pub key is added as a wallet public key in jwt token to use. Note: This parameter won't change format of private key returned by auth. Private key returned by auth is always secp256k1.
dappUrlAllows the dapp to set a custom redirect url for the manage mfa flow.

Further, for Custom Authentication, ExtraLoginOptions can be used to pass the standard OAuth login options.

ExtraLoginOptions
ParameterDescription
domainYour Auth0 account domain such as 'example.auth0.com', 'example.eu.auth0.com' or , 'example.mycompany.com' (when using custom domains)
client_idThe Client ID found on your Application settings page
redirect_uriThe default URL where Auth0 will redirect your browser to with the authentication result. It must be whitelisted in the "Allowed Callback URLs" field in your Auth0 Application's settings. If not provided here, it should be provided in the other methods that provide authentication.
leewayThe value in seconds used to account for clock skew in JWT expirations. Typically, this value is no more than a minute or two at maximum. Defaults to 60s.
verifierIdFieldThe field in jwt token which maps to verifier id
isVerifierIdCaseSensitiveWhether the verifier id field is case sensitive
additionalParamsIf you need to send custom parameters to the Authorization Server, make sure to use the original parameter name.
display- 'page': displays the UI with a full page view - 'popup': displays the UI with a popup window - 'touch': displays the UI in a way that leverages a touch interface - 'wap': displays the UI with a "feature phone" type interface
prompt- 'none': do not prompt user for login or consent on re-authentication - 'login': prompt user for re-authentication - 'consent': prompt user for consent before processing request - 'select_account': prompt user to select an account
max_ageMaximum allowable elapsed time (in seconds) since authentication. If the last time the user authenticated is greater than this value, the user must be re-authenticated.
ui_localesThe space-separated list of language tags, ordered by preference. For example: 'fr-CA fr en'.
id_token_hintPreviously issued ID Token.
login_hintThe user's email address or other identifier. When your app knows which user is trying to authenticate, you can provide this parameter to pre-fill the email box or select the right session for sign-in. This currently only affects the classic Lock experience.
acr_values
scopeThe default scope to be used on authentication requests. The defaultScope defined in the Auth0Client is included along with this scope
audienceThe default audience to be used for requesting API access.
connectionThe name of the connection configured for your application. If null, it will redirect to the Auth0 Login Page and show the Login Widget.

Check if the user is connected

connected

You can check if the user is connected to the blockchain by calling the connected method on the web3auth instance. This property method a boolean value.

const isConnected = web3auth.connected;

Returns

connected: boolean;
tip

If you're using the uxMode: "redirect" option within your configuration, you need to check this event to handle the logging in implicitly. This is because, when redirected to a different application, the app state is not updated as per the login status.

Using this method, you can check if the user is connected and update the app state accordingly within the constructor.

Check which adapter is connected

connectedAdapterName

This function gives you the name of the connected adapter. This can be used to check which adapter is connected to the user.

const adapter = web3auth.connectedAdapterName;

Returns

connectedAdapterName: WALLET_ADAPTER_TYPE | null;

export type WALLET_ADAPTER_TYPE = (typeof WALLET_ADAPTERS)[keyof typeof WALLET_ADAPTERS];

export declare const WALLET_ADAPTERS: {
AUTH: string;
WALLET_CONNECT_V2: string;
SFA: string;
TORUS_SOLANA: string;
TORUS_EVM: string;
COINBASE: string;
};
  • If a user is connected, it will return the name of the adapter via which the login has happened.
  • If connecting via MIPD (EIP6163) in default evm/ solana adapters, it will return the name of the wallet connected.
  • If no user is connected, this function will return a null value.

Get the connected provider

provider

Returns the private key provider connected to the web3auth instance.

Returns

provider: IProvider | null;
  • If a user is connected, it will return the provider instance connected to the user.
  • If no user is connected, however, the initialisation of the web3auth instance is done, it will return the provider instance, however the provider cannot be used for any operations.
  • If no user is connected and the web3auth instance is not initialised, it will return a null value.
note

To know more in-depth about providers, have a look at the Providers reference.

Know the current status of the instance

status

Returns the current status of the web3auth instance.

const status = web3auth.status;

An adapter emits certain events like CONNECTED, CONNECTING and DISCONNECTED etc during login lifecycle of a user. Knowing to events help you trigger responses based on the status of the connection of the user. For example, you can use this to show an error message, if the user is not connected to the network.

Web3Auth provides the following lifecycle event to check the login status:

EventDescription
NOT_READYTriggered when the adapter is not ready.
READYTriggered when the adapter is ready.
CONNECTINGTriggered when the user is connecting to the wallet.
CONNECTEDTriggered when the user is connected to the wallet.
ERROREDTriggered when an error occurs during the login lifecycle.

Get User's Information

getUserInfo()

You can get the information about connected user by calling getUserInfo() function.

note

This function will only return information based on the connected adapter. These details are not stored anywhere and are fetched from the adapter during the connection and remain in the session.

await web3auth.getUserInfo();

Returns

VariableTypeDescription
emailstringEmail of the user.
namestringName of the user.
profileImagestringProfile image of the user.
aggregateVerifierstringAggregate verifier of the user.
verifierstringVerifier of the user.
verifierIdstringVerifier ID of the user.
typeOfLoginstringType of login provider.
dappSharestringDapp share of the user.
idTokenstringToken issued by Web3Auth.
oAuthIdTokenstringToken issued by OAuth provider. Will be available only if you are using custom verifiers.
oAuthAccessTokenstringAccess Token issued by OAuth provider. Will be available only if you are using custom verifiers.
appStatestringApp state of the user.
touchIDPreferencestringTouch ID preference of the user.
isMfaEnabledbooleanWhether Multi Factor Authentication is enabled for the user.

Sample Response

{
"email": "john@gmail.com",
"name": "John Dash",
"profileImage": "https://lh3.googleusercontent.com/a/Ajjjsdsmdjmnm...",
"aggregateVerifier": "tkey-google-lrc",
"verifier": "torus",
"verifierId": "john@gmail.com",
"typeOfLogin": "google",
"dappShare": "<24 words seed phrase>", // will be sent only incase of custom verifiers
"idToken": "<jwtToken issued by Web3Auth>",
"oAuthIdToken": "<jwtToken issued by OAuth Provider>", // will be sent only incase of custom verifiers
"oAuthAccessToken": "<accessToken issued by OAuth Provider>" // will be sent only incase of custom verifiers
}

Enable Multi Factor Authentication (MFA)

enableMFA()

You can enable Multi Factor Authentication for the user by calling the enableMFA() function. This function will trigger a redirect to the MFA setup page, where the user will be asked to login again and set up the MFA Methods according to the configuration set in the web3auth instance.

await web3auth.enableMFA();

Interface

enableMFA<T>(loginParams?: T): Promise<void>;

Get idToken

authenticateUser()

You can get the idToken from Web3Auth by calling authenticateUser() function.

note

This function will only return information based on the connected adapter. These details are not stored anywhere and are fetched from the adapter during the connection and remain in the session.

await web3auth.authenticateUser();

Returns

ParameterTypeDescription
iatnumberThe "iat" (issued at) claim identifies the time at which the JWT was issued.
audstringThe "aud" (audience) claim identifies the recipients that the JWT is intended for. (Here, it's the dapp client_id)
issstringThe "iss" (issuer) claim identifies who issued the JWT. (Here, it's Web3Auth https://api.openlogin.com/)
emailstringThe email address of the user (optional)
namestringThe name of the user (optional)
profileImagestringThe profile image of the user (optional)
verifierstringWeb3auth's verifier used while user login
verifierIdstringUnique user id given by OAuth login provider
aggregateVerifierstringName of the verifier if you are using a single id verifier (aggregateVerifier) (optional)
expnumberThe "exp" (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing.
walletsarraylist of wallets for which this token is issued:
  • curve "secp256k1" (default) or "ed25519"
    You can specify which curve you want use for the encoded public key in the login parameters
  • type "web3auth_key" incase of social logins
  • public_key compressed public key derived based on the specified curve

Sample Response

{
"iat": 1655835494,
"aud": "BCtbnOamqh0cJFEUYA0NB5YkvBECZ3HLZsKfvSRBvew2EiiKW3UxpyQASSR0artjQkiUOCHeZ_ZeygXpYpxZjOs",
"iss": "https://api.openlogin.com/",
"email": "xyz@xyz.com",
"name": "John Doe",
"profileImage": "https://lh3.googleusercontent.com/a/AATXAJx3lnGmHiM4K97uLo9Rb0AxOceH-dQCBSRqGbck=s96-c",
"verifier": "torus",
"verifierId": "xyz@xyz.com",
"aggregateVerifier": "tkey-google-lrc",
"exp": 1655921894,
"wallets": [
{
"public_key": "035143318b83eb5d31611f8c03582ab1200494f66f5e11a67c34f5581f48c1b70b",
"type": "web3auth_key",
"curve": "secp256k1"
}
]
}

Add Chain

addChain()

To add a chain config to a connected adapter, you need to call addChain() function. This function helps you add the chain config by taking the following parameter:

VariableDescription
chainConfigCustomChainConfig for the chain you want to add.
await web3auth.addChain({
chainId: "0xaa36a7",
displayName: "Ethereum Sepolia",
chainNamespace: CHAIN_NAMESPACES.EIP155,
tickerName: "Sepolia",
ticker: "ETH",
decimals: 18,
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
blockExplorerUrl: "https://sepolia.etherscan.io",
logo: "https://images.toruswallet.io/eth.svg",
isTestnet: true,
});

Switch Chain

switchChain()

To switch the Chain to the added chain config, you need to call switchChain() function. This function takes the following parameter:

VariableDescription
{ chainId: "0xaa36a7" }chainId of the added chain config, e.g { chainId: "0xaa36a7" }
await web3auth.switchChain({ chainId: "0xaa36a7" });

Logging out the User

web3auth.logout()

You can disconnect from connected wallet using logout function.

await web3auth.logout();

Type Reference

logout(options?: { cleanup: boolean; }): Promise<void>;

Connecting to a Blockchain

For Connecting to Blockchain and making RPC calls within your dApp, you can use the IProvider instance returned while logging in the user. This instance gives you the respective provider for your selection of blockchain. This provider can be used to interact with the connected chain using exposed functions within the provider.

Web3Auth is chain agnostic, ie. be it any chain you're connecting to, you can use Web3Auth to connect to it. You can use the EVM or Solana provider, that contain the native functions to connect to the blockchain or use the private key directly to connecting to the respective blockchain.

Currently web3auth supports providers for both EVM and Solana chains. For other chains, one can easily get the private key from the base provider from Web3Auth.

Fetching the Connected Adapter

connectedAdapterName

This function gives you the name of the connected adapter. This can be used to check which adapter is connected to the user.

const adapter = web3auth.connectedAdapterName;

Returns

connectedAdapterName: WALLET_ADAPTER_TYPE | null;

export type WALLET_ADAPTER_TYPE = (typeof WALLET_ADAPTERS)[keyof typeof WALLET_ADAPTERS];

export declare const WALLET_ADAPTERS: {
AUTH: string;
WALLET_CONNECT_V2: string;
SFA: string;
TORUS_SOLANA: string;
TORUS_EVM: string;
COINBASE: string;
};
  • If a user is connected, it will return the name of the adapter via which the login has happened.
  • If connecting via MIPD (EIP6163) in default evm/ solana adapters, it will return the name of the wallet connected.
  • If no user is connected, this function will return a null value.

Wallet Services Plugin Methods

You can use the Wallet Services Plugin to enable additional functionalities like showing the Wallet UI Screen, Wallet Connect Scanner, and initiating topup for the user.

tip

Learn more about the Wallet Services Plugin in the Wallet Services SDK Reference.

Show WalletConnect Scanner

You can use the showWalletConnectScanner function to show the Wallet Connect Scanner, and connect with dApps having Wallet Connect login option. This is useful for interoperability with dApps having Wallet Connect login option. Learn more about showWalletConnectScanner.

Fiat On Ramp

You can use the showCheckout function to show the TopUp modal, allowing users to select their local currency and specify the token to top up their wallet. Learn more about showCheckout.

Embedded Wallet UI

You can use the showWalletUI function to show the templated wallet UI services. Learn more about showWalletUI.

Transaction Confirmatons Screen

You can use the wallet services provider to integrate prebuilt transaction confirmation screens into your application. Upon successful completion, you can retrieve the signature for the request. Learn more about transaction confirmation screens.