Pregenerating an embedded wallet
You can pregenerate a non-custodial wallet associated with a given account, such as an email address or third-party authentication provider, without requiring the user to log in. You can send assets to the wallet before the user logs in for the first time. Once the user logs in, they can access the pregenerated wallet and any assets sent to them.
Users claim their pregenerated wallet by logging into your app with one of the linked accounts.
EVM with email
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.openfort.io/api-keys
import Openfort, { ShieldAuthProvider } from '@openfort/openfort-node';
const openfort = new Openfort(YOUR_SECRET_KEY);
// Pregenerate an EVM embedded wallet using email
const account = await openfort.accounts.evm.embedded.pregenerate(
{
email: "[email protected]",
},
{
shieldAuthProvider: ShieldAuthProvider.OPENFORT,
shieldApiKey: 'YOUR_SHIELD_API_KEY',
shieldApiSecret: 'YOUR_SHIELD_API_SECRET',
encryptionShare: 'YOUR_SHIELD_ENCRYPTION_SHARE',
}
)Solana with email
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.openfort.io/api-keys
import Openfort, { ShieldAuthProvider } from '@openfort/openfort-node';
const openfort = new Openfort(YOUR_SECRET_KEY);
// Pregenerate a Solana embedded wallet using email
const account = await openfort.accounts.solana.embedded.pregenerate(
{
email: "[email protected]",
},
{
shieldAuthProvider: ShieldAuthProvider.OPENFORT,
shieldApiKey: 'YOUR_SHIELD_API_KEY',
shieldApiSecret: 'YOUR_SHIELD_API_SECRET',
encryptionShare: 'YOUR_SHIELD_ENCRYPTION_SHARE',
}
)Provide one of the following user identification methods:
email: the user's email address when using Openfort authentication.thirdPartyUserIdandthirdPartyProvider: the user's ID and provider when using a third-party authentication service such as Firebase, Supabase, or Auth0. Both fields are required when using this method.
For the shield configuration:
shieldAuthProvider: set toShieldAuthProvider.OPENFORT.shieldApiKey: your Shield API key from the dashboard.shieldApiSecret: your Shield API secret from the dashboard.encryptionShare: your Shield encryption share.
A successful response includes the new embedded account object along with the user's ID:
EVM Response
{
"id": "acc_ff54b031-a878-4ca2-9cf5-ae190f921e9b",
"user": "usr_ff54b031-a878-4ca2-9cf5-ae190f921e9b",
"address": "0x1234567890abcdef1234567890abcdef12345678",
"ownerAddress": "0xabcdef1234567890abcdef1234567890abcdef12",
"accountType": "Externally Owned Account",
"chainType": "EVM",
"createdAt": 1691658234
}