No matter how your user signs up, whether it’s through social login such as Telegram, email or phone, or a branded wallet like MetaMask, you can create an embedded wallet for them using Dynamic. Simply choose when you want the wallet to be created and follow the guides below.
Please make sure you are on v4.20.6 before continuing.
During Signup (Automatic)
Creating Embedded Wallets
By default, embedded wallets are created automatically for users during sign-up if they don’t already have a wallet on the enabled chain. All you have to do is check that the “Create on Sign up” toggle is turned on in the Embedded Wallet configuration page.
Automatic embedded wallet creation only creates a single wallet for a user on each chain you have selected. For information on how to create multiple wallets, see the “Creating Wallets Any Time” section below.
Creating Wallets for users with External Wallets
You can automatically create embedded wallets for users who sign in with external wallets like MetaMask. To enable this feature, open the “Create on Sign Up” card, expand the “Advanced Options” panel, and turn on the “Embedded Wallet for Third-Party Wallets” toggle.
Custom Logic (Manual)
Check if User has an Embedded Wallet
React
React Native
Swift
Flutter
You can check if a user has an embedded wallet by using the useDynamicWaas hook.
const { userHasEmbeddedWallet } = useDynamicWaas();
if (userHasEmbeddedWallet) {
console.log('User has an embedded wallet');
}
You can check if a user has an embedded wallet using wallets.embedded.hasWallet.import { dynamicClient } from '<path to client file>';
import { useReactiveClient } from '@dynamic-labs/react-hooks';
// within a component
const { wallets } = useReactiveClient(dynamicClient)
const userHasEmbeddedWallet = wallets.embedded.hasWallet;
if (userHasEmbeddedWallet) {
console.log('User has an embedded wallet');
}
You can check if a user has an embedded wallet by inspecting their verifiedCredentials.import DynamicSwiftSDK
let dynamicClient: DynamicClient
// Get user's verified credentials and filter for blockchain wallets
if let verifiedCredentials = dynamicClient.user?.verifiedCredentials {
let hasWallet = verifiedCredentials.contains { $0.format == .blockchain }
if hasWallet {
print("User has an embedded wallet")
} else {
print("User does not have an embedded wallet")
}
}
You can check if a user has an embedded wallet using DynamicSDK.instance.wallets.embedded.hasWallet.import 'package:dynamic_sdk/dynamic_sdk.dart';
final userHasEmbeddedWallet = DynamicSDK.instance.wallets.embedded.hasWallet;
if (userHasEmbeddedWallet) {
print('User has an embedded wallet');
} else {
print('User does not have an embedded wallet');
}
Creating Wallets Any Time
If you do not want to create wallets for users automatically when they sign up, you can create wallets for users using custom logic.
React
React Native
Swift
Flutter
To do so, call the createWalletAccount method from the useDynamicWaas hook when you want to create a wallet for a user.You can control which chains you create wallets on by passing an array of chains to the createWalletAccount method. See the useDynamicWaas documentation for more details. import { useDynamicWaas, useUserWallets } from "@dynamic-labs/sdk-react-core";
import { ChainEnum } from "@dynamic-labs/sdk-api-core";
// component declaration and all other logic you might need
const { createWalletAccount, getWaasWallets } = useDynamicWaas();
const onCreateWalletHandler = async () => {
try {
const waasWallets = await getWaasWallets();
if (waasWallets.length === 0) {
await createWalletAccount([ChainEnum.Evm, ChainEnum.Sol]);
}
} catch (e) {
console.error(e);
}
};
To create a wallet, call the createWallet method. You can optionally specify a chain.import { dynamicClient } from '<path to client file>';
// Create a wallet on the default chain
await dynamicClient.wallets.embedded.createWallet();
// Or, create a wallet for a specific chain
await dynamicClient.wallets.embedded.createWallet({ chain: 'Evm' });
To create a new wallet for an authenticated user, use the createWalletAccount function.import DynamicSwiftSDK
let dynamicClient: DynamicClient
// Create a new wallet account
do {
let accountAddress = try await createWalletAccount(client: dynamicClient)
print("✅ Wallet created successfully!")
print("Account Address: \(accountAddress)")
} catch {
print("❌ Failed to create wallet: \(error)")
}
To create a wallet, call the createWallet method.import 'package:dynamic_sdk/dynamic_sdk.dart';
try {
final wallet = await DynamicSDK.instance.wallets.embedded.createWallet();
print('Wallet created: ${wallet.address}');
} catch (e) {
print('Error creating wallet: $e');
}
Creating Wallets with a Passcode
You can create MPC wallets that are protected with a user chosen passcode for additional security. When a wallet is created with a passcode, certain operations (like signing transactions or exporting keys) will require the passcode to be provided.
To create a passcode-protected wallet, pass a password string as the second parameter to createWalletAccount:import { useDynamicWaas } from "@dynamic-labs/sdk-react-core";
import { ChainEnum } from "@dynamic-labs/sdk-api-core";
const { createWalletAccount } = useDynamicWaas();
const onCreateSecureWalletHandler = async () => {
try {
// Create a passcode-protected wallet for EVM
const secureWallet = await createWalletAccount(
[ChainEnum.Evm],
'your-strong-passcode'
);
console.log('Secure wallet created:', secureWallet);
} catch (e) {
console.error('Error creating secure wallet:', e);
}
};
Important Considerations
- User Experience: Consider the trade-off between security and user experience when requiring passcodes for operations.
- Backup: When using passcodes, ensure users understand the importance of backing up their wallets and passcodes.