Using the JS SDK
Configure Openfort's embedded wallets in your application with two steps:
- Configure the embedded wallet.
- Wait for the signer to be ready.
Waiting for ready
When calling embeddedWallet.configure, embeddedWallet.create or embeddedWallet.recover, the SDK will go through a series of states before it is ready to be used. These states are represented by the enum:
| State | Description |
|---|---|
| 0 - NONE | The initial state of the SDK. |
| 1 - UNAUTHENTICATED | Before the user is authenticated. |
| 2 - EMBEDDED_SIGNER_NOT_CONFIGURED | Before calling embeddedWallet.configure. |
| 3 - CREATING_ACCOUNT | If no account exists for the current chainID, when it will be created. |
| 4 - READY | The embedded wallet is ready to be used |
As a consequence, it's important to wait until the embeddedState has finished initializing before you use the embedded wallet, to ensure that the state you consume is accurate and not stale.
To determine whether the Openfort SDK has initialized the embedded wallet, you can call the method embeddedWallet.getEmbeddedState and check if the state is READY:
main.ts
import openfort from "./openfortConfig";
const state = await openfort.embeddedWallet.getEmbeddedState();