EmbeddedWallet
Wallet interface to connect Embedded Wallet which allows developers to implement seamless onboarding and login flows for their users.
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);
> {}
The options for instantiating an EmbeddedWallet
The options object contains the following properties:
clientId (required)
The chain to connect to by default.
Must be a Chain object, from the @thirdweb-dev/chains package.
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.
Authenticate the user with any of the available auth strategies.
const authResult = await wallet.authenticate({ strategy: "google",});
Choose one of the available auth strategy, which comes with different required arguments.
// email verificationtype 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 authenticationtype JwtAuthParams = { strategy: "jwt"; jwt: string; encryptionKey?: string;}; // open iframe to send and input the verification code onlytype IframeOtpAuthParams = { strategy: "iframe_email_verification"; email: string;}; // open iframe to enter email and verification codetype IframeAuthParams = { strategy: "iframe";};
The authResult object - which you can pass to the connect method to connect to the wallet.
const authResult = await wallet.authenticate(authOptions);await wallet.connect({ authResult });
auto connect the wallet if the wallet was previously connected and session is still valid
function autoConnect(): Promise<string>;
After authenticating, you can connect to the wallet by passing the authResult to the connect method.
const authResult = await wallet.authenticate(authOptions); await wallet.connect({ authResult });
function connect(): Promise<string>;
The connectOptions object contains the following properties:
authResult (required)
The authResult object is returned from the authenticate method.
Get the instance of EmbeddedWalletSdk used by the wallet.
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",});
This method is also available as a static method on the EmbeddedWallet class.
const result = await EmbeddedWallet.sendVerificationEmail({ email: "alice@example.com",});
function sendVerificationEmail(options: { email: string;
object containing below properties:
{ isNewDevice: boolean; isNewUser: boolean; recoveryShareManagement: "USER_MANAGED" | "AWS_MANAGED";}
isNewDevice
If user has not logged in from this device before, this will be true.
isNewUser
If user is logging in for the first time, this will be true.
recoveryShareManagement
Recovery share management type. Can be either USER_MANAGED or AWS_MANAGED .
Send a verification code to the user's phone number for verification. The phone number must contain the country code.
Use this as a pre-step before calling authenticate with the phone_number_verification strategy.
const result = await wallet.sendVerificationSms({ phoneNumber: "+1234567890",});
This method is also available as a static method on the EmbeddedWallet class.
const result = await EmbeddedWallet.sendVerificationSms({ phoneNumber: "+1234567890",});
function sendVerificationSms(options: { phoneNumber: string;
object containing below properties:
{ isNewDevice: boolean; isNewUser: boolean; recoveryShareManagement: "USER_MANAGED" | "AWS_MANAGED";}
isNewDevice
If user has not logged in from this device before, this will be true.
isNewUser
If user is logging in for the first time, this will be true.
recoveryShareManagement
Recovery share management type. Can be either USER_MANAGED or AWS_MANAGED .
Sends a verification email to the provided email address.
EmbeddedWallet.sendVerificationEmail({ email: "test@example.com", clientId: "yourClientId",}) .then(() => console.log("Verification email sent successfully.")) .catch((error) => console.error("Failed to send verification email:", error), );
function sendVerificationEmail(options: { clientId: string; email: string;
Information on the user's status and whether they are a new user.
Sends a verification sms to the provider phone number.
const result = await EmbeddedWallet.sendVerificationEmail({ phoneNumber: "+1234567890", clientId: "yourClientId",});
function sendVerificationSms(options: { clientId: string; phoneNumber: string;
Information on the user's status and whether they are a new user.
AbstractClientWallet.addListenerfunction addListener( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.emitCalls each of the listeners registered for a given event.
function emit( event: T,): boolean;
AbstractClientWallet.eventNamesReturn an array listing the events for which the emitter has registered listeners.
AbstractClientWallet.getBalanceReturns the balance of the connected wallet for the specified token address. If no token address is specified, it returns the balance of the native token
function getBalance( tokenAddress: string,): Promise<{ decimals: number; displayValue: string; name: string; symbol: string; value: BigNumber;}>;
AbstractClientWallet.getPersonalWalletIf the wallet uses another "personal wallet" under the hood, return it
This is only useful for wallets like Safe or Smart Wallet uses a "personal wallet" under the hood to sign transactions. This method returns that wallet
AbstractClientWallet.getSignerGet ethers Signer object of the connected wallet
function getSigner(): Promise<Signer>;
AbstractClientWallet.listenerCountReturn the number of listeners listening to a given event.
AbstractClientWallet.listenersReturn the listeners registered for a given event.
function listeners( event: T,): Array< ( ) => void>;
let returnType: Array< ( ) => void>;
AbstractClientWallet.offfunction off( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.onAdd a listener for a given event.
function on( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.onceAdd a one-time listener for a given event.
function once( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.removeListenerRemove the listeners of a given event.
function removeListener( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.transferTransfers some amount of tokens to the specified address
function transfer( to: string, amount: string | number, currencyAddress: string,): Promise<Omit<TransactionResultWithMetadata<unknown>, "data">>;
AbstractClientWallet.updateChainsUpdate the chains supported by the wallet. This is useful if wallet was initialized with some chains and this needs to be updated without re-initializing the wallet
function updateChains(chains: Array<Chain>): Promise<void>;
AbstractClientWallet.verifySignature Verify the signature of a message. It returns true if the signature is valid, false otherwise
function verifySignature( message: string, signature: string, address: string, _chainId?: number,): Promise<boolean>;