Skip to main content
The @privy-io/js-sdk-core library is a vanilla JavaScript library for browser-like environments. It provides secure authentication, non-custodial embedded wallets, and user management without requiring React or any other UI framework.
@privy-io/js-sdk-core is a low-level library. Please do not attempt to use this library without first reaching out to the Privy team to discuss your project and which Privy SDK options may be better suited to it.

Prerequisites

Before you begin:
  • Set up your Privy app and obtain your app ID from the Privy Dashboard
  • Obtain your client ID from the Dashboard under Settings → Clients

Installation

1. Create the Privy client

Import the Privy class and create a single instance for your application. The client accepts the following configuration:
Only instantiate a single Privy client for your application. Creating multiple instances will cause unexpected behavior.
The Storage interface requires four methods. Implement this interface if LocalStorage is not suitable for your environment (e.g., encrypted storage, server-side rendering, or non-browser runtimes):

2. Initialize the client

After creating the client, call initialize() to establish a connection with the Privy backend and restore any existing session. This must complete before performing any other operations.
After initialize() resolves, call client.user.get() to check for an existing authenticated session. If the user previously logged in and the session is still valid, this returns the user object without requiring re-authentication.

Restoring a returning user’s session

3. Connect to the secure context

The Privy secure context is an iframe that handles embedded wallet key material. Your app must mount this iframe and wire up bidirectional message passing.

Mount the iframe

Wire up message passing

If you are using a UI rendering library or framework, render the iframe and register event listeners using that library’s lifecycle methods instead of manipulating the DOM directly.

4. Authenticate a user

The Privy core SDK supports email, SMS, OAuth, and JWT-based authentication.

5. Get access tokens for your backend

After authentication, use getAccessToken() to retrieve the user’s access token. Include this token in requests to your backend to verify the user’s identity.
getAccessToken() automatically handles token refresh when the access token is near expiration. The returned token is always valid at the time of return.

6. Create an embedded wallet

Your app can manually create wallets for users when desired.
Privy can provision wallets for your users on both Ethereum and Solana.

7. Connect to an existing wallet

When a user returns to your app on a subsequent visit, the wallet already exists but a provider must be obtained.

8. Use the embedded wallet

Your wallet must have funds to pay for gas. Use a testnet faucet to test on Base Sepolia, or send funds to the wallet on your preferred network.
With the embedded wallet provider, your app can prompt the user to sign messages and send transactions.
Learn more about sending transactions with the embedded wallet. Privy enables you to take many actions on the embedded wallet, including sign a message, sign typed data, and sign a transaction.

9. Log the user out

To end the user’s session and clean up resources:
After logout, the user must authenticate again to access any protected resources or wallet functionality.

Full integration example

Below is a minimal end-to-end integration showing the complete lifecycle: