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:
The chain to connect to by default.
Must be a Chain
object, from the @thirdweb-dev/chains
package.
The chain to connect to by default.
Must be a Chain
object, from the @thirdweb-dev/chains
package.
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:
The authResult
object is returned from the authenticate
method.
Get the email associated with the currently connected wallet.
```javascriptconst email = await wallet.getEmail();
function getEmail(): Promise<undefined | string>;
Get the instance of EmbeddedWalletSdk
used by the wallet.
Get the phone number associated with the currently connected wallet.
```javascriptconst email = await wallet.getPhoneNumber();
function getPhoneNumber(): Promise<undefined | string>;
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({});
This method is also available as a static method on the EmbeddedWallet
class.
const result = await EmbeddedWallet.sendVerificationEmail({});
function sendVerificationEmail(options: { email: string;
object containing below properties:
{ isNewDevice: boolean; isNewUser: boolean; recoveryShareManagement: "USER_MANAGED" | "AWS_MANAGED";}
If user has not logged in from this device before, this will be true.
If user is logging in for the first time, this will be true.
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";}
If user has not logged in from this device before, this will be true.
If user is logging in for the first time, this will be true.
Recovery share management type. Can be either USER_MANAGED
or AWS_MANAGED
.
Sends a verification email to the provided email address.
EmbeddedWallet.sendVerificationEmail({ 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.addListener
function addListener( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.disconnect
Disconnect the wallet
function disconnect(): Promise<void>;
AbstractClientWallet.emit
Calls each of the listeners registered for a given event.
function emit( event: T,): boolean;
AbstractClientWallet.eventNames
Return an array listing the events for which the emitter has registered listeners.
AbstractClientWallet.getAddress
Returns the account address of the connected wallet
function getAddress(): Promise<string>;
AbstractClientWallet.getBalance
Returns 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.getChainId
Returns the chain id of the network that the wallet is connected to
function getChainId(): Promise<number>;
AbstractClientWallet.getPersonalWallet
If 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.getSigner
Get ethers Signer object of the connected wallet
function getSigner(): Promise<Signer>;
AbstractClientWallet.listenerCount
Return the number of listeners listening to a given event.
AbstractClientWallet.listeners
Return the listeners registered for a given event.
function listeners( event: T,): Array< ( ) => void>;
let returnType: Array< ( ) => void>;
AbstractClientWallet.off
function off( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.on
Add a listener for a given event.
function on( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.once
Add a one-time listener for a given event.
function once( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.removeListener
Remove the listeners of a given event.
function removeListener( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.signMessage
Sign a message with the connected wallet and return the signature
function signMessage(message: string | Bytes): Promise<string>;
AbstractClientWallet.switchChain
Switch to different Network/Blockchain in the connected wallet
function switchChain(chainId: number): Promise<void>;
AbstractClientWallet.transfer
Transfers some amount of tokens to the specified address
function transfer( to: string, amount: string | number, currencyAddress: string,): Promise<Omit<TransactionResultWithMetadata<unknown>, "data">>;
AbstractClientWallet.updateChains
Update 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>;
let walletId: string;
let prefixed: string | boolean;