Use this file to discover all available pages before exploring further.
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.
A custom logger object to replace the default console-based logger. Useful for routing Privy logs
to your observability stack.
Custom storage adapters
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):
import type {Storage} from '@privy-io/js-sdk-core';const myStorage: Storage = { get(key: string): Promise<string | null> { /* return value for key, or null */ }, put(key: string, val: string): Promise<void> { /* persist key-value pair */ }, del(key: string): Promise<void> { /* delete key */ }, getKeys(): Promise<string[]> { /* return all stored keys */ }};
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.
try { await privy.initialize();} catch (e) { // Initialization can fail if storage access is blocked or network is unavailable console.error('Privy initialization failed:', e);}
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.
await privy.initialize();// Check if a user is already logged in from a previous sessionconst {user} = await privy.user.get();if (user) { // Store the user object in your application state (e.g., a store, context, or signal) // This is the source of truth for the authenticated user throughout your app} else { // No active session — prompt the user to log in}
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.
// Allow the Privy client to post messages to the iframeprivy.setMessagePoster(iframe.contentWindow);// Forward messages from the iframe to the Privy clientwindow.addEventListener('message', (e) => { // Only process messages from the Privy iframe if (e.source !== iframe.contentWindow) return; const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data; privy.embeddedWallet.onMessage(data);});
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.
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.
const {user} = await privy.user.get();await privy.auth.logout({userId: user.id});// Clean up the iframe and event listenerswindow.removeEventListener('message', listener);iframe.remove();
After logout, the user must authenticate again to access any protected resources or wallet functionality.