Management API Reference

Using the Openfort SDKs

There are two steps to configure Openfort in your application:

  • Configure the embedded signer configuration.
  • Wait for the embedded signer to be ready.

Embedded signer configuration#

The Openfort SDKs provide a way to configure a non-custodial embedded signer that can be used to sign transactions and interact with the blockchain. The configureEmbeddedSigner is the method responsible for setting up and creating the non-custodial wallet.

config.ts
openfortConfig.ts

_12
import { ShieldAuthType } from '@openfort/openfort-js';
_12
import openfort from "./openfortConfig"
_12
_12
// This example assumes that the user is `authenticated`
_12
async function configure(password:string, auth_token:string){
_12
const chainId = 80002;
_12
const shieldAuth = {
_12
auth: ShieldAuthType.OPENFORT,
_12
token: auth_token,
_12
};
_12
await openfort.configureEmbeddedSigner(chainId, shieldAuth, password);
_12
}

The configureEmbeddedSigner will include a chainID parameter, which is the identifier of the blockchain network you want to interact with and create an embedded signer there. You can read the list of supported chains here.

Let's go over the rest of the shieldAuth parameters of the configureEmbeddedSigner method:

ParameterDescription
authDefines how the token parameter is going to be verified. Can be either openfort or custom, defining if the token is going to be verified by Openfort or by another backend.
tokenThe access_token or id_token that will be used to verify that the user is logged in in your application.

Automatic embedded signer creation: to offer a frictionless onboarding, you can enlable automatic embedded signer creation. Learn more about it how to enable automatic recovery.

Waiting for ready#

When calling configureEmbeddedSigner, the SDK will go through a series of states before it is ready to be used. These states are represented by the enum:

StateDescription
0 - NONEThe initial state of the SDK.
1 - UNAUTHENTICATEDBefore the user is authenticated.
2 - EMBEDDED_SIGINER_NOT_CONFIGUREDBefore calling the configureEmbeddedSigner.
3 - CREATING_ACCOUNTIf no account exists for the current chainID, when it will be created.
4 - READYThe embedded signer is ready to be used

As a consequence, it's important to wait until the embeddedState has finished initializing before you use the embedded signer, to ensure that the state you consume is accurate and not stale.

To determine whether the Openfort SDK has initialized the embedded signer, you can call the method getEmbeddedState and check if the state is READY:

main.ts
openfortConfig.ts

_10
import openfort from "./openfortConfig"
_10
_10
const state = openfort.getEmbeddedState()