The @privy-io/js-sdk-core library is a vanilla JavaScript library, intended for use in a browser-like environment, it allows you to add secure authentication, non-custodial embedded wallets, and powerful user management into your application.

@privy-io/js-sdk-core library is a low-level JavaScript 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, make sure you have set up your Privy app and obtained your app ID from the Privy Dashboard.

Installation

npm install @privy-io/js-sdk-core@latest

Getting a Privy instance

Import the Privy class and create an instance of it, passing the Privy app ID and app client ID and storage adapter. You may also configure any EVM chains you would like to support.

import Privy, {LocalStorage} from '@privy-io/js-sdk-core';

new Privy({
  appId,
  clientId,
  supportedChains,
  storage: new LocalStorage()
});

You should ensure that there is only ever one instance of the Privy client instantiated for your app.

Connecting to the secure context

Configure the Privy SDK with the Privy iframe to be able to provision non-custodial embedded wallets for your users.

First, create and mount an iframe in your app, use the Privy client to get the src URL.

const iframeUrl = privy.embeddedWallet.getURL();
const iframe = document.createElement('iframe');
iframe.src = iframeUrl;
document.body.appendChild(iframe);

Then, pass through a reference to the iframe to the Privy client and attach listeners for message events.

privy.setMessagePoster(iframe.contentWindow);
const listener = (e) => privy.embeddedWallet.onMessage(e.data);
window.addEventListener('message', listener);

If you are using a UI rendering library or framework we recommend rendering the iframe and registering listener using that library instead of using the DOM directly.

Authentication

The Privy core SDK supports a variety of authentication options including email, SMS, OAuth and JWT-based auth.

const emailAddress = 'insert-user-email-address';
await privy.auth.email.sendCode(emailAddress);
const emailOTP = 'insert-otp-collected-from-user';
const session = await privy.auth.email.loginWithCode(emailAddress, emailOTP);

Creating a 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.
const {user} = await privy.embeddedWallet.create();
const wallet = getUserEmbeddedEthereumWallet(user);
const {entropyId, entropyIdVerifier} = getEntropyDetailsFromUser(user);
const provider = await privy.embeddedWallet.getEthereumProvider({
  wallet,
  entropyId,
  entropyIdVerifier
});

Using the embedded wallet

In order to send a transaction, your wallet must have some funds to pay for gas. You can use a testnet faucet to test transacting on a testnet (e.g. Base Sepolia) or send funds to the wallet on the network of your choice.

With the users’ embedded wallet, your application can now prompt the user to sign and send transactions.

const provider = await privy.embeddedWallet.getEthereumProvider({...args});
await provider.request({
  method: 'personal_sign',
  params: ['hello', signingAddress]
});

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.