Skip to main content

Getting Started with the Web SDK

Naming

Embedded Wallets SDKs were previously known as Web3Auth Plug and Play SDKs. Package names and APIs remain Web3Auth (for example, @web3auth/modal).

Overview

Embedded Wallets provide a seamless authentication experience for web applications with social logins, external wallets, and more. Using our JavaScript SDK, you can easily connect users to their preferred wallets and manage authentication state.

Requirements

  • This is a frontend SDK and must be used in a browser environment.
  • Basic knowledge of JavaScript.

Prerequisites

tip

See the dashboard setup guide to learn more.

Installation

Install the Web3Auth Modal SDK using npm or yarn:

npm install --save @web3auth/modal

1. Configuration

Create an instance of Embedded Wallets containing the basic required configuration. This configuration will contain your Embedded Wallets Client ID and network details from the Embedded Wallets dashboard.

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

const web3auth = new Web3Auth({
clientId: 'YOUR_WEB3AUTH_CLIENT_ID', // Pass your Embedded Wallets/Web3Auth Client ID, ideally using an environment variable // Get your Client ID from Embedded Wallets dashboard
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, // or WEB3AUTH_NETWORK.SAPPHIRE_DEVNET
})

2. Initialize Embedded Wallets

Initialize the Web3Auth instance before using any authentication methods:

await web3auth.init()

Advanced configuration

The Web3Auth Modal SDK offers a rich set of advanced configuration options:

tip

See the advanced configuration section to learn more about each configuration option.

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

const web3auth = new Web3Auth({
clientId: 'YOUR_WEB3AUTH_CLIENT_ID', // Pass your Web3Auth Client ID, ideally using an environment variable
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, // or WEB3AUTH_NETWORK.SAPPHIRE_DEVNET
})

Blockchain integration

Web3Auth is blockchain agnostic, enabling integration with any blockchain network. Out of the box, Web3Auth offers robust support for both Solana and Ethereum, each with dedicated provider methods.

Solana integration

To interact with Solana networks, you can get the provider from Web3Auth and use it with Solana libraries:

await web3auth.connect()
// Use with a Solana library
const solanaWallet = new SolanaWallet(web3auth.provider)

Ethereum integration

For Ethereum integration, you can get the provider and use it with ethers or viem:

await web3auth.connect()
// Use with ethers.js
const ethPovider = new ethers.BrowserProvider(web3auth.provider)
// OR
// Use with viem
const walletClient = createWalletClient({
chain: getViewChain(web3auth.provider),
transport: custom(web3auth.provider),
})

Troubleshooting

Bundler issues: missing dependencies

You might encounter errors related to missing dependencies in the browser environment:

  • Buffer is not defined
  • process is not defined
  • Other Node.js-specific modules missing errors

These Node.js dependencies need to be polyfilled in your application. See the detailed troubleshooting guides for popular bundlers:

JWT errors

When using custom authentication, you may encounter JWT errors: