Headless Embedded Wallets With OTP
Summary
This guide will show you how to create an embedded wallet for a user, then help them secure it once they are ready to make their first transaction using One Time Codes, and optionally adding a passkey.
When using one time codes, we’ll also create a session for that user so they can transact for a further period of time without any extra steps. for more information on the differences between passkeys and one codes, please see this guide.
We will assume that the user has already signed up. If you need to handle the signup part headlessly, we recommend reading the headless email guide.
Here are the steps we need to follow:
- Check for active session
- Create the embedded wallet
- Secure the wallet pre-transaction
- Create a session for the user
For all of these steps we will need just one hook - useEmbeddedWallet
.
Pre-requisites
- You have already set up the Dynamic SDK and wrapped your app with the
DynamicContextProvider
. - You have enabled Dynamic-powered embedded wallets and toggled “Create on Sign up” on in the configuration.
- You do not have the DynamicWidget component in your application code.
Session Notes
For security reasons, sessions are held in an iframe which gets deleted after page refresh and user log out.
To overcome sending users one-time codes each time they don’t have an active session, we’re able to restore it and developers should always try to do it before starting the one-time codes flow.
You’ll see this in the code examples below, where we check for an active session before sending the one-time code i.e.
Full code examples
You must add the following to your root CSS file to hide the iframe
Was this page helpful?