Skip to main content

Getting Started with Web3Auth SDK

Overview

Web3Auth Plug and Play (PnP) provides 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.

Installation

Install the Web3Auth Modal SDK using npm or yarn:

npm install --save @web3auth/modal

Setup

info

Prerequisites Before you start, make sure you have registered on the Web3Auth Dashboard and have set up your project. You can look into the Dashboard Setup guide to learn more.

1. Configuration

Create an instance of Web3Auth containing the basic needed configuration. These configuration will contain your Web3Auth Client ID and Network details from the Web3Auth Dashboard.

import { Web3Auth, WEB3AUTH_NETWORK } from "@web3auth/modal";

const web3auth = new Web3Auth({
clientId: "YOUR_CLIENT_ID", // Get your Client ID from Web3Auth Dashboard
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, // or WEB3AUTH_NETWORK.SAPPHIRE_DEVNET
});

2. Initialize Web3Auth

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

Head over to the Advanced Configuration section to learn more about each configuration option.

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 ethProvider = new ethers.BrowserProvider(web3auth.provider);
// OR
// Use with viem
const walletClient = createWalletClient({
chain: getViewChain(web3auth.provider),
transport: custom(web3auth.provider),
});
import { Web3Auth, WEB3AUTH_NETWORK } from "@web3auth/modal";

const web3auth = new Web3Auth({
clientId: "YOUR_CLIENT_ID",
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, // or WEB3AUTH_NETWORK.SAPPHIRE_DEVNET
});

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. We've prepared detailed troubleshooting guides for popular bundlers:

JWT Errors

When using Custom Authentication, you may encounter JWT errors:

Different Private Keys Across Integrations

If you're getting different private keys across integrations, see our guide on Different Private Keys across integrations.

Quick Starts