Summary
A React hook that provides functionality for managing Dynamic MPC wallets. This hook enables wallet creation, management, and interaction with Dynamic’s embedded wallet system.Return Value
Functions
createWalletAccount
Creates wallet accounts for enabled chains in the project settings. This function can create wallets for one or more specified chains. Optionally accepts a password (passcode) to create a passcode-protected wallet.chainNames?
: ChainEnum[] - Optional. When omitted, creates wallets for all enabled chains.password?
: string - Optional passcode to protect the wallet.
- Creates wallet accounts for the specified chains in parallel
- After creation, it will:
- Find the primary wallet account (based on the chain marked as primary in settings)
- Refresh the user data to get the latest wallet information
- Update the primary wallet to the newly created wallet
- Close any open auth flow modals
NO_ENABLED_CHAINS_ERROR
if no chains are enabled in the project settingsDYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR
if a wallet connector is not found for an enabled chain- Any errors from the underlying wallet creation process
getWalletConnector
Retrieves a configured wallet connector for a specific chain.chainName
: string - The name of the chain to get the connector for.
IDynamicWaasConnector
or undefined
if:
- Cookie auth is disabled and no auth token is present
- No wallet connector options are available
- The environment ID is not set
DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR
if the wallet connector is not found.
importPrivateKey
Imports a private key for a specific chain.chainName
: string - The name of the chain to import the private key for.privateKey
: string - The private key to import.
- Imports the private key for the specified chain
- Refreshes the user data after successful import
- Returns undefined if the wallet connector is not found
getWaasWallets
Finds all Dynamic WaaS wallets associated with the user.- Filters the user’s wallets to only return those with
key === 'dynamicwaas'
- Returns an empty array if no Dynamic WaaS wallets are found
- The returned wallets can be used for chain-specific operations (e.g., transactions)
upgradeToDynamicWaas
Upgrades the users current primary wallet (assuming it’s legacy) to a Dynamic WaaS wallet.privateKey
: string - The private key of the legacy embedded wallet to upgrade, must be associated with the user’s current primary wallet.wallet
: Wallet - The wallet to upgrade.
Primary wallet not found
if the primary wallet is not foundWallet connector not found
if the wallet connector is not foundUpgrade failed
if there are any errors from the underlying wallet upgrade process
- Upgrades the legacy embedded wallet associated with the private key to a Dynamic MPC wallet
- Removes access to the previous legacy embedded wallet and replaces it with a new Dynamic embedded wallet
- This is a one-way upgrade. Once a user has upgraded to v3 and received a new v3 wallet, they will lose access to their v1 or v2 embedded wallet.
- We recommend that you prompt your user to confirm they do not have any funds in their wallet before making this switch.
- The user must be logged in, and the private key must be associated with the user’s current primary wallet.
Properties
dynamicWaasIsEnabled
Indicates whether Dynamic WaaS is enabled in the project settings.shouldAutoCreateDynamicWaasWallet
Indicates whether a Dynamic WaaS wallet should be automatically created.Important Notes
-
Authentication Requirements:
- The hook requires either cookie authentication or a valid auth token to function properly.
- Wallet connector operations will return undefined if authentication is not available.
-
Chain Configuration:
- Wallet creation and operations require properly configured chains in the project settings.
- At least one chain must be enabled for wallet creation to work.
-
Version Compatibility:
- Dynamic WaaS is only enabled when using EmbeddedWalletVersionEnum.V3.
- The hook will not function with older wallet versions (V1 or V2).
-
Auto-Creation Behavior:
- Auto-creation of wallets is controlled by project settings.
- Separate settings exist for external wallet users.
- Auto-creation will not occur if the user already has a Dynamic WaaS wallet.
-
Relay Configuration:
- The hook uses a relay URL for wallet operations, which can be configured in project settings.
- If not specified, it defaults to ‘relay.dynamic-preprod.xyz’.