Pregenerating an embedded wallet
You can pregenerate non-custodial wallet associated with a given account, like an email address or social login, without requiring the user to login. You can even send assets to the wallet before the user logs in to your app for the first time. Once the user associated with the account logs in, they will be able to access the pregenerated wallet and any assets sent to them. To pregenerate wallets, use one of the supported backend SDKs:
A user can easily claim their pregenerated wallet simply by logging into your app with one of its linked accounts.
Node.js
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.openfort.io/developers/configuration/api-keys
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
const notifications = await openfort.iam.createAuthPlayer(
{
thirdPartyUserId: "user id",
thirdPartyProvider: 'provider name', // Id of the provider of the user
preGenerateEmbeddedAccount: true
chainId: 4337,
metadata: {
name: "Jaume"
}
},
{
shieldAuthProvider: '', // ShieldAuthProvider.OPENFORT or ShieldAuthProvider.CUSTOM
apiKey: '', // Shield publishable key
apiSecret: '', // Shield secret key
encryptionPart: '' // Shield encryption share
})
In the body of the request:
thirdPartyUserId
: the user's account id.thirdPartyProvider
: the provider used: custom, supabase, oidc, etc.preGenerateEmbeddedAccount
: boolean with the value true.
A successful response will include the new user object along with their user's ID (playerID
), as shown in the Response tab above.
Response
{
"id": "pla_ff54b031-a878-4ca2-9cf5-ae190f921e9b",
"object": "player",
"createdAt": 1691658234,
"linkedAccounts": [
{
"provider": "email",
"email": "jaume@openfort.io",
"disabled": false,
"updatedAt": 1691658234
}
]
}