useEmbeddedWallet
This hook gives you control over when you create an embedded wallet for any given user, the ability to check if a user currently has an embedded wallet, the ability to create and validate user sessions, and other helpful methods.
You can also utilize the methods in combination with each other to create a fully headless implementation of embedded wallet onboarding flows, check out the headless embedded guides for more.
Usage
Create embedded wallet
Create an embedded wallet at any point.
Method Signature
Example
Create embedded wallet account
Used to create an embedded wallet on an additional chain if a user already has an embedded wallet on another chain.
Create session
Create an embedded wallet session whenever you need to validate the user authenticity to perform transactions without the need to prompt user confirmation every single time.
Steps
- First you need to trigger the sending of a one-time code for authenticity validation, the
sendOneTimeCode
method handles this. - Once the user enters the one-time code, the
createOrRestoreSession
method will initiate a session as long as the code is valid.
Create passkey
Create a passkey whenever you need to validate the user authenticity to perform a transaction or to access a specific feature as well as to handle cases where the user lost access to their device.
Steps
- If the user is not in an active session, we first need to send them a one-time code for authenticity validation.
- Once the user enters the one-time code, the
createPasskey
method will validate it and create a passkey.
Return Values
- createEmbeddedWallet returns a promise which will resolve to a wallet ID once the creation flow has been successful.
- createEmbeddedWalletAccount returns a promise which will resolve to a user once the creation flow has been successful.
- createOrRestoreSession returns a promise which will resolve to a string
session_created
orsession_restored
if the session has been created or restored successfully. - createPasskey returns a promise which will resolve to a passkey data
(attestation, challenge, displayName)
once the creation flow has been successful. - getPasskeys returns a promise which will resolve to an array of passkeys info.
- isLoadingEmbeddedWallet returns a boolean which will be true if the embedded wallet is being created.
- isSessionActive returns a boolean which will be true if the user has an active session.
- sendOneTimeCode returns a promise which will resolve to a string
code_sent
if the code has been sent successfully. - userHasEmbeddedWallet returns a boolean which will be true if the user has an embedded wallet at that time.
Was this page helpful?