Skip to main content

Embedded Wallet

Prompt users to connect to your app using their email with Embedded Wallet.

Usage

import { EmbeddedWallet } from "@thirdweb-dev/wallets";
import { Ethereum } from "@thirdweb-dev/chains";

const wallet = new EmbeddedWallet({
chain: Ethereum, // chain to connect to
clientId: "YOUR_CLIENT_ID", // client ID
});

const authResult = await wallet.authenticate({
strategy: "google",
});

const walletAddress = await wallet.connect({ authResult });
console.log("Connected as", walletAddress);

Configuration

Provide a configuration object when instantiating the EmbeddedWallet class.

clientId (required)

The embedded wallet requires a clientId. You can create a clientId by visiting the Dashboard. To learn more about API keys, visit the API key documentation.

Must be a string.

chain (required)

The chain to connect to by default.

Must be a Chain object, from the @thirdweb-dev/chains package.

chains (optional)

Provide an array of chains you want to support.

Must be an array of Chain objects, from the @thirdweb-dev/chains package.

Methods

Inherits all the public methods from the AbstractClientWallet class.

authenticate

Authenticate the user with any of the available auth strategies.

const authResult = await wallet.authenticate({
strategy: "google",
});
Configuration

Choose one of the available auth strategy, which comes with different required arguments.

// email verification
type EmailVerificationAuthParams = {
strategy: "email_verification";
email: string;
verificationCode: string;
recoveryCode?: string;
};

export type EmbeddedWalletOauthStrategy = "google" | "apple" | "facebook";

type OauthAuthParams = {
strategy: EmbeddedWalletOauthStrategy;
openedWindow?: Window;
closeOpenedWindow?: (window: Window) => void;
};

// bring your own authentication
type JwtAuthParams = {
strategy: "jwt";
jwt: string;
encryptionKey?: string;
};

// open iframe to send and input the verification code only
type IframeOtpAuthParams = {
strategy: "iframe_email_verification";
email: string;
};

// open iframe to enter email and verification code
type IframeAuthParams = {
strategy: "iframe";
};

connect

After authenticating, you can connect to the wallet by passing the authResult to the connect method.

await wallet.connect({ authResult });
Configuration
Returns the associated wallet address of the user.

getEmail

Get the email associated with the currently connected wallet.

const email = await wallet.getEmail();

sendVerificationEmail

Send a verification code to the user's email for verification. Use this as a prestep before calling authenticate with the email_verification strategy.

const result = await wallet.sendVerificationEmail({
email: "alice@example.com",
});